gen

package
v0.0.0-...-8b81d4d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventNameField        humus.Predicate = "Event.name"
	EventAttendingField   humus.Predicate = "Event.attending"
	EventPricesField      humus.Predicate = "Event.prices"
	EventDescriptionField humus.Predicate = "Event.description"
	EventPremiumField     humus.Predicate = "~Event.attending|premium"
)

Generating constant field values.

View Source
const (
	UserNameField      humus.Predicate = "User.name"
	UserEmailField     humus.Predicate = "User.email"
	UserFullNameField  humus.Predicate = "User.fullName"
	UserAttendingField humus.Predicate = "~Event.attending"
	UserPremiumField   humus.Predicate = "Event.attending|premium"
)

Generating constant field values.

View Source
const (
	ErrorMessageField   humus.Predicate = "Error.message"
	ErrorErrorTypeField humus.Predicate = "Error.errorType"
	ErrorTimeField      humus.Predicate = "Error.time"
)

Generating constant field values.

Variables

View Source
var ErrorFields humus.Fields = humus.FieldList([]humus.Field{MakeField("Error.message", 0), MakeField("Error.errorType", 0), MakeField("Error.time", 0)})
View Source
var EventFields humus.Fields = humus.FieldList([]humus.Field{MakeField("Event.name", 0), MakeField("Event.attending", 0|humus.MetaObject|humus.MetaList|humus.MetaReverse), MakeField("Event.prices", 0|humus.MetaList), MakeField("Event.description", 0), MakeField("~Event.attending|premium", 0|humus.MetaFacet)})
View Source
var UserFields humus.Fields = humus.FieldList([]humus.Field{MakeField("User.name", 0), MakeField("User.email", 0), MakeField("User.fullName", 0), MakeField("~Event.attending", 0|humus.MetaObject|humus.MetaList|humus.MetaReverse), MakeField("Event.attending|premium", 0|humus.MetaFacet)})

Functions

func AddUserToEvent

func AddUserToEvent(euid humus.UID, userUid humus.UID, premium int) bool

Adds a user to an event from a http endpoint. Premium facet.

func GetField

func GetField(name humus.Predicate) humus.Field

func GetGlobalFields

func GetGlobalFields() map[humus.Predicate]humus.Field

func MakeField

func MakeField(name humus.Predicate, flags humus.FieldMeta) humus.Field

Types

type Error

type Error struct {
	//This line declares basic properties for a database node.
	humus.Node
	//Regular fields
	Message   string     `json:"message" predicate:"Error.message,omitempty"`
	ErrorType string     `json:"errorType" predicate:"Error.errorType,omitempty"`
	Time      *time.Time `json:"time" predicate:"Error.time,omitempty"`
}

//Values returns all the scalar values for this node.

func (r *User) Values() humus.DNode{
   var m UserScalars
   m.Name= r.Name
       m.Email= r.Email
       m.FullName= r.FullName
       m.Premium= r.Premium
       r.SetType()
   m.Node = r.Node
   return &m
}

//Values returns all the scalar values for this node. //Note that this completely ignores any omitempty tags so use with care.

func (r *User) MapValues() humus.Mapper {
   var m = make(map[string]interface{})
   m["User.name"]= r.Name
      m["User.email"]= r.Email
      m["User.fullName"]= r.FullName
      m["Event.attending|premium"]= r.Premium
      if r.Uid != "" {
      m["uid"] = r.Uid
   }
    r.SetType()
    m["dgraph.type"] = r.Type
    return m
}

//UserScalars is simply to avoid a map[string]interface{} //It is a mirror of the previous struct with all scalar values.

type UserScalars struct {
    humus.Node
    Name string `json:"User.name,omitempty"`
    Email string `json:"User.email,omitempty"`
    FullName string `json:"User.fullName,omitempty"`
    Premium int `json:"Event.attending|premium,omitempty"`

}

func (s *UserScalars) Values() humus.DNode {
    return s
}
func (s *UserScalars) Fields() humus.FieldList {
    return UserFields
}

End of model.template

func (*Error) Facets

func (r *Error) Facets() []string

func (*Error) Fields

func (r *Error) Fields() humus.Fields

Fields returns all Scalar fields for this value.

func (*Error) GetType

func (r *Error) GetType() []string

SaveValues saves the node values that do not contain any references to other objects. Not needed for now.

func (r *Error) SaveValues(ctx context.Context, txn *humus.Txn) error {
    mut := humus.CreateMutation(r.Values(), humus.MutateSet)
    _,err := txn.Mutate(ctx, mut)
    return err
}

func (*Error) Recurse

func (r *Error) Recurse(counter int) int

Recurse iterates through the node and allocates type and UID to pointer nodes.

func (*Error) Reset

func (r *Error) Reset()

Reset resets the node to only its UID component. Useful for saving to the database. Calling this function ensures that, at most, the uid and type is serialized.

func (*Error) SetType

func (r *Error) SetType()

Sets the types. This DOES NOT include interfaces! as they are set in dgraph already.

type Event

type Event struct {
	//This line declares basic properties for a database node.
	humus.Node
	//Regular fields
	Name        string  `json:"name" predicate:"Event.name,omitempty"`
	Attending   []*User `json:"attending" predicate:"Event.attending,omitempty"`
	Prices      []int   `json:"prices" predicate:"Event.prices,omitempty"`
	Description string  `json:"description" predicate:"Event.description,omitempty"`
	Premium     int     `json:"premium" predicate:"~Event.attending|premium,omitempty"`
}

func EventOrderByPremium

func EventOrderByPremium(uid humus.UID) (*Event, error)

func GetEvent

func GetEvent(uid humus.UID) ([]*Event, error)

func NewEvent

func NewEvent(eventName string, description string, prices []int) (*Event, error)

func (*Event) Facets

func (r *Event) Facets() []string

func (*Event) Fields

func (r *Event) Fields() humus.Fields

Fields returns all Scalar fields for this value.

func (*Event) GetType

func (r *Event) GetType() []string

SaveValues saves the node values that do not contain any references to other objects. Not needed for now.

func (r *Event) SaveValues(ctx context.Context, txn *humus.Txn) error {
    mut := humus.CreateMutation(r.Values(), humus.MutateSet)
    _,err := txn.Mutate(ctx, mut)
    return err
}

func (*Event) Recurse

func (r *Event) Recurse(counter int) int

Recurse iterates through the node and allocates type and UID to pointer nodes.

func (*Event) Reset

func (r *Event) Reset()

Reset resets the node to only its UID component. Useful for saving to the database. Calling this function ensures that, at most, the uid and type is serialized.

func (*Event) SetType

func (r *Event) SetType()

Sets the types. This DOES NOT include interfaces! as they are set in dgraph already.

type User

type User struct {
	//This line declares basic properties for a database node.
	humus.Node
	//Regular fields
	Name      string   `json:"name" predicate:"User.name,omitempty"`
	Email     string   `json:"email" predicate:"User.email,omitempty"`
	FullName  string   `json:"fullName" predicate:"User.fullName,omitempty"`
	Attending []*Event `json:"attending" predicate:"~Event.attending,omitempty"`
	Premium   int      `json:"premium" predicate:"Event.attending|premium,omitempty"`
}

//Values returns all the scalar values for this node.

func (r *Event) Values() humus.DNode{
   var m EventScalars
   m.Name= r.Name
       m.Prices= r.Prices
       m.Description= r.Description
       m.Premium= r.Premium
       r.SetType()
   m.Node = r.Node
   return &m
}

//Values returns all the scalar values for this node. //Note that this completely ignores any omitempty tags so use with care.

func (r *Event) MapValues() humus.Mapper {
   var m = make(map[string]interface{})
   m["Event.name"]= r.Name
      m["Event.prices"]= r.Prices
      m["Event.description"]= r.Description
      m["~Event.attending|premium"]= r.Premium
      if r.Uid != "" {
      m["uid"] = r.Uid
   }
    r.SetType()
    m["dgraph.type"] = r.Type
    return m
}

//EventScalars is simply to avoid a map[string]interface{} //It is a mirror of the previous struct with all scalar values.

type EventScalars struct {
    humus.Node
    Name string `json:"Event.name,omitempty"`
    Prices []int `json:"Event.prices,omitempty"`
    Description string `json:"Event.description,omitempty"`
    Premium int `json:"~Event.attending|premium,omitempty"`

}

func (s *EventScalars) Values() humus.DNode {
    return s
}
func (s *EventScalars) Fields() humus.FieldList {
    return EventFields
}

End of model.template

func GetUserWithAttending

func GetUserWithAttending(name string) (*User, error)

func NewUser

func NewUser(name string) (*User, error)

func (*User) Facets

func (r *User) Facets() []string

func (*User) Fields

func (r *User) Fields() humus.Fields

Fields returns all Scalar fields for this value.

func (*User) GetType

func (r *User) GetType() []string

SaveValues saves the node values that do not contain any references to other objects. Not needed for now.

func (r *User) SaveValues(ctx context.Context, txn *humus.Txn) error {
    mut := humus.CreateMutation(r.Values(), humus.MutateSet)
    _,err := txn.Mutate(ctx, mut)
    return err
}

func (*User) Recurse

func (r *User) Recurse(counter int) int

Recurse iterates through the node and allocates type and UID to pointer nodes.

func (*User) Reset

func (r *User) Reset()

Reset resets the node to only its UID component. Useful for saving to the database. Calling this function ensures that, at most, the uid and type is serialized.

func (*User) SetType

func (r *User) SetType()

Sets the types. This DOES NOT include interfaces! as they are set in dgraph already.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL