humus

package module
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: 22 Imported by: 0

README

Get started

Install the code generator using go get.

go get github.com/Vliro/humus/gen  

Specify a schema

#spec/schema.graphql
interface Post {   
 text: String! @search (by:[hash])   
 datePublished: DateTime!   
}   
    
type Question implements Post {   
 title: String! @search (by:[hash])   
 from: User!   
}   
    
type User {   
 name: String!   
}  

Generate code

Spec is an example folder where relevant GraphQL files lie and models is just an example output.

$GOPATH/bin/gen -input=spec/ -output=models/

#schema.txt
type Post {   
 Post.text : string   
 Post.datePublished : datetime   
}   
type Question {   
 Question.title : string   
 Question.from : User   
}   
type User {   
 User.name : string   
}   
<Post.text>: string @index(hash)  .   
<Post.datePublished>: datetime  .   
<Question.title>: string @index(hash)  .   
<Question.from>: uid  .   
<User.name>: string  .   

Generate structs

Code below is an extract from the generated code.

//models/models.go
//...  
type Question struct {  
 //This line declares basic properties for a database node.  
 humus.Node  
 //List of interfaces implemented.  
 Post  
 //Regular fields  
 Title string `json:"Question.title,omitempty"`  
 From  *User  `json:"Question.from,omitempty"`  
}  
//...  

Run a query

Run an example query.

//Gets question top level values as well as the edge Question.from.  
var getFields = QuestionFields.Sub(QuestionFrom, UserFields)  
//Get all questions in the database.  
func GetAllQuestions() ([]*Question, error) {  
 var p []*Question  
 var q = humus.NewQuery(getFields).  
 Function(humus.Type).Value("Question")  
 err := db.Query(context.Background(), q, &p)  
 return p, err  
}  

Understand the code

gen is the folder containing all code pertaining to generating Go code from GraphQL specifications.
testing contains all test code.
//WIP examples contains example usages of the library.

All code is documented over at Godoc.
https://godoc.org/github.com/Vliro/humus

Documentation

Index

Constants

View Source
const (
	LanguageEnglish = "en"
	LanguageGerman  = "de"
	LanguageSwedish = "se"
	//Same as english.
	LanguageNone = ""
)

A list of possible languages. TODO: Do not make these static constants. Allow arbitrary languages.

Variables

View Source
var ErrUID = errors.New("missing UID")

Functions

func Error

func Error(err error) error

Call this on a top level error.

Types

type AggregateType

type AggregateType string

AggregateType simply refers to all types of aggregation as specified in the query docs.

const (
	Val   AggregateType = ""
	Min   AggregateType = "min"
	Sum   AggregateType = "sum"
	Max   AggregateType = "max"
	Avg   AggregateType = "avg"
	Count AggregateType = "count"
)

Types of aggregations.

type AsyncQuerier

type AsyncQuerier interface {
	Querier
	QueryAsync(context.Context, Query, ...interface{}) chan Result
	MutateAsync(context.Context, Query) chan Result
}

AsyncQuerier is an interface representing a querier that can also perform queries asynchronously.

type Config

type Config struct {
	//IP for this alpha.
	IP string
	//Port for this alpha.
	Port int
	//Tls connection.
	Tls bool
	//RootCA is the path for the RootCA.
	RootCA string
	//NodeCRT is the path for the NodeCRT.
	NodeCRT string
	//NodeKey is the path for the NodeKey.
	NodeKey string
	//Log queries in stdout along their result.
	LogQueries bool
}

Config represents the configuration for connecting to a Dgraph alpha client.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is the root object for using humus. It is used to immediately communicate with Dgraph as well as spawning new transactions. It handles a pool of dgraph clients as well as the active schema for the database.

func Init

func Init(conf *Config, sch SchemaList) *DB

Init is the entrypoint for humus. Init creates a a database object using the connection information as specified in the config. It uses the information specified to set up a grpc connection to the specified destination with or without TLS. It also sets the database schema using a pregenerated schema from humus/gen. Any query or mutation to the database goes through this object.

func (*DB) Alter

func (d *DB) Alter(ctx context.Context, op *api.Operation) error

Alter runs the command given by op to the dgraph instance.

func (*DB) Cleanup

func (d *DB) Cleanup()

Cleanup should be deferred at the main function.

func (*DB) Commit

func (d *DB) Commit(ctx context.Context) error

Commit is a noop.

func (*DB) Discard

func (d *DB) Discard(ctx context.Context) error

Discard is a noop.

func (*DB) Mutate

func (d *DB) Mutate(ctx context.Context, m Mutate) (*api.Response, error)

Mutate runs a mutation outside a transaction context. It immediately commits on success.

func (*DB) NewTxn

func (d *DB) NewTxn(readonly bool) *Txn

NewTxn creates a new txn for interacting with database.

func (*DB) OnAborted

func (d *DB) OnAborted(f func(query interface{}))

OnAborted sets the function for which to call when returned error is errAborted. The query variable is either a Mutate or a Query and should be handled accordingly.

func (*DB) OnError

func (d *DB) OnError(f func(err error, val interface{}))

OnError sets the function to be called on error from dgraph.

func (*DB) Query

func (d *DB) Query(ctx context.Context, q Query, objs ...interface{}) error

Query queries outside a Txn context.

func (*DB) QueryAsync

func (d *DB) QueryAsync(ctx context.Context, q Query, objs ...interface{}) chan Result

QueryAsync runs the query and returns a channel with the result.

func (*DB) Schema

func (d *DB) Schema() SchemaList

Schema returns the active schema for this database.

func (*DB) Select

func (d *DB) Select(vals ...Predicate) Fields

Select allows you to create a field list of only certain predicates. It is recommended to select from generated field lists as it s run at init and causes less overhead in queries.

func (*DB) SetValue

func (d *DB) SetValue(node DNode, pred Predicate, value interface{}) error

SetValue is a simple wrapper to set a single value in the database for a given node. It exists for convenience.

type DNode

type DNode interface {
	//Returns the UID of this node.
	UID() UID
	//Sets the UID of this node.
	SetUID(uid UID)
	//Sets all types of this node. This has to be done at least once.
	SetType()
	//Returns the type.
	GetType() []string
	//Returns all fields for this node.
	Fields() Fields
	//Serializes all the scalar values that are not hidden. It usually returns
	//a type of *{{.typ}}Scalars.
	//Values() DNode
	//Recurse allows you to set types and UIDS for all sub nodes.
	Recurse(counter int) int
}

DNode represents an object that can be safely stored in the database. It includes all necessary fields for automatic generation. This is a big interface but it is automatically satisfied by all values.

type Deleter

type Deleter interface {
	Delete() (DNode, error)
}

Deleter allows you to implement a custom delete method.

type Directive

type Directive string

Directive contains all possible query directives for dgraph. These are applied at the root of the query.

const (
	Cascade      Directive = "cascade"
	Normalize    Directive = "normalize"
	IgnoreReflex Directive = "ignorereflex"
)

type Field

type Field struct {
	Meta   FieldMeta
	Fields Fields
	Name   Predicate
}

Field is a recursive data struct which represents a GraphQL query field.

func MakeField

func MakeField(name Predicate, meta FieldMeta) Field

MakeField constructs a Field of given name and returns the Field.

func (Field) Add

func (f Field) Add(fi Field) Fields

func (Field) Get

func (f Field) Get() []Field

func (Field) Len

func (f Field) Len() int

func (Field) Select

func (f Field) Select(names ...Predicate) Fields

func (Field) Sub

func (f Field) Sub(name Predicate, fields Fields) Fields

Sub here simply uses fields as Field { fields}. That is, you use this if you only want to get a relation. Name here does not matter actually.

type FieldList

type FieldList []Field

func (FieldList) Add

func (f FieldList) Add(fi Field) Fields

func (FieldList) AddName

func (f FieldList) AddName(nam Predicate, sch SchemaList) Fields

func (FieldList) Get

func (f FieldList) Get() []Field

func (FieldList) Len

func (f FieldList) Len() int

func (FieldList) Select

func (f FieldList) Select(names ...Predicate) Fields

Select allows you to perform selection of fields early, at init. This removes the Ignore meta from any field selected to allow password fields.

func (FieldList) Sub

func (f FieldList) Sub(name Predicate, fl Fields) Fields

Sub allows you to add sub-field structures.

type FieldMeta

type FieldMeta uint16

A meta field for schemas. This simply defines properties surrounding fields such as language etc. This is used in generating the queries.

const (
	MetaObject FieldMeta = 1 << iota
	MetaList
	MetaLang
	MetaUid
	MetaReverse
	MetaFacet
	MetaEmpty
	MetaIgnore
)

func (FieldMeta) Empty

func (f FieldMeta) Empty() bool

func (FieldMeta) Facet

func (f FieldMeta) Facet() bool

func (FieldMeta) Ignore

func (f FieldMeta) Ignore() bool

func (FieldMeta) Lang

func (f FieldMeta) Lang() bool

func (FieldMeta) List

func (f FieldMeta) List() bool

func (FieldMeta) Object

func (f FieldMeta) Object() bool

func (FieldMeta) Reverse

func (f FieldMeta) Reverse() bool

type Fields

type Fields interface {
	//Sub allows you to create a sublist of predicates.
	//If there is an edge on a predicate name, then subbing on that
	//predicate gets all fields as specified by the fields interfaces.
	Sub(name Predicate, fields Fields) Fields
	//Add a field to this list.
	Add(fi Field) Fields
	//Get the fields as a slice
	Get() []Field
	//Len is the length of the fields.
	Len() int
	Select(names ...Predicate) Fields
}
FieldList is a list of fields associated with a generated object.
These are of global type and should never be modifierType lest
the state of the entire application should be changed.
Whenever fields are added to this list they are copied.
Example usage:
var NewFields = CharacterFields.Sub("Character.friends", CharacterFields).Sub("Character.enemies", CharacterFields.
				Sub("Character.items", ItemFields)
This will also ensure fields are copied properly from the global list.

Fields is an interface for all possible type of fields. This includes global fields as well as manually generated fields.

func Select

func Select(sch SchemaList, names ...Predicate) Fields

Select selects a subset of fields and returns a new list keeping all valid meta.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter represents an object in the query that will be serialized as @filter (function...) It is just a wrapper over a function.

func (*Filter) Values

func (f *Filter) Values(v ...interface{}) *Filter

Values is a wrapper to add a list of values to this filter.

type FunctionType

type FunctionType string
const (
	Equals      FunctionType = "eq"
	AllOfText   FunctionType = "alloftext"
	AllOfTerms  FunctionType = "allofterms"
	AnyOfTerms  FunctionType = "anyofterms"
	FunctionUid FunctionType = "uid"
	Has         FunctionType = "has"
	LessEq      FunctionType = "le"
	Match       FunctionType = "match"
	Less        FunctionType = "lt"
	GreaterEq   FunctionType = "ge"
	Greater     FunctionType = "gt"
	Type        FunctionType = "type"
)

func (FunctionType) WithFunction

func (f FunctionType) WithFunction(typ string) FunctionType

WithFunction creates an in/equality function with a subfunction. Possible values for typ is count and val. For instance, cases with lt(count(predicate),1). would be Less.WithFunction("count") with two function variables, predicate, 1.

type GeneratedQuery

type GeneratedQuery struct {
	// contains filtered or unexported fields
}

GeneratedQuery is the root object of queries that are constructed. It is constructed using a set of Fields that are either autogenerated or manually specified. From its list of modifiers(orderby, pagination etc) it automatically and efficiently builds up a query ready for sending to Dgraph.

func GetByPredicate

func GetByPredicate(pred Predicate, fields Fields, values ...interface{}) *GeneratedQuery

GetByPredicate is shorthand for generating a query for getting nodes from multiple predicate values given by the fields.

func GetByUid

func GetByUid(uid UID, fields Fields) *GeneratedQuery

GetByUid is shorthand for generating a query for getting a node from its uid given by the fields.

func NewQuery

func NewQuery(f Fields) *GeneratedQuery

NewQuery returns a new singular generation query for use in building a single query.

func (*GeneratedQuery) At

At allows you to run modifiers at a path. Modifiers include pagination, sorting, filters among others.

func (*GeneratedQuery) Directive

func (q *GeneratedQuery) Directive(dir Directive) *GeneratedQuery

Directive adds a top level directive.

func (*GeneratedQuery) Facets

func (q *GeneratedQuery) Facets(path Predicate, op Operation) *GeneratedQuery

Facets sets @facets for the edge specified by path along with all values as specified by op. This can be used to fetch facets, store facets in query variables or something in that manner. For instance, generating a line in the fashion of @facets(value as friendsSince) will store the facet value 'friendsSince' into the value variable 'value'.

func (*GeneratedQuery) Function

func (q *GeneratedQuery) Function(ft FunctionType) *GeneratedQuery

Function sets the function type for this function. It is used alongside variables. variables are automatically mapped to GraphQL variables as a way of avoiding SQL injections.

func (*GeneratedQuery) GroupBy

func (q *GeneratedQuery) GroupBy(path Predicate, onWhich Predicate, op Operation) *GeneratedQuery

GroupBy allows you to groupBy at a leaf field. Using op specify a list of variables and operations to be written as aggregation at this level. onWhich specifies what predicate to actually group on.

func (*GeneratedQuery) Language

func (q *GeneratedQuery) Language(l Language, strict bool) *GeneratedQuery

Language sets the language for the query to apply to all fields. If strict do not allow untagged language.

func (*GeneratedQuery) Process

func (q *GeneratedQuery) Process() (string, error)

func (*GeneratedQuery) Static

func (q *GeneratedQuery) Static() StaticQuery

Static create a static query from the generated version. Since this is performed at init, panic if the query creation does not work.

func (*GeneratedQuery) Values

func (q *GeneratedQuery) Values(v ...interface{}) *GeneratedQuery

Values simple performs the same as Value but for a variadic number of arguments.

func (*GeneratedQuery) Var

func (q *GeneratedQuery) Var(name string) *GeneratedQuery

Var sets q as a var query with the variable name name. if name is empty it is just a basic var query.

type Language

type Language string

Language represents a language that sets relevant queries to the language as specified.

type Mapper

type Mapper map[string]interface{}

Mapper allows you to set subrelations manually.

func NewMapper

func NewMapper(uid UID, typ []string) Mapper

NewMapper returns a map as a Dnode. This is useful for building up custom structures. For completely custom mutations see CreateCustomMutation. Types are not mandatory but should be supplied for new nodes.

func (Mapper) Fields

func (m Mapper) Fields() Fields

func (Mapper) GetType

func (m Mapper) GetType() []string

func (Mapper) MustSet

func (m Mapper) MustSet(child Predicate, all bool, obj DNode) Mapper

MustSet panics on a nil node. Otherwise it is the same as Set.

func (Mapper) Recurse

func (m Mapper) Recurse(counter int) int

func (Mapper) Set

func (m Mapper) Set(child Predicate, all bool, obj DNode) Mapper

Set sets a singular regulation, i.e. 1-1. If all uses saver interface or the entire object. Otherwise, only uid is used.

func (Mapper) SetArray

func (m Mapper) SetArray(child string, all bool, objs ...DNode) Mapper

SetArray sets a list of edges, saving as the form [node1, node2..].

func (Mapper) SetFunctionValue

func (m Mapper) SetFunctionValue(variableName string, predicate Predicate)

SetFunctionValue is used in relation to upsert. For instance, storing uid in "result" variable. This will set the value on the edge predicate to the value. This is a simple case and for more complicated queries manually edit the Mapper to look correct. If predicate is "uid" do not set it as a child relation.

func (Mapper) SetType

func (m Mapper) SetType()

func (Mapper) SetUID

func (m Mapper) SetUID(uid UID)

func (Mapper) UID

func (m Mapper) UID() UID

UID returns the uid for this map.

type Mod

type Mod interface {
	/*
		Paginate creates a pagination at this level given the pagination type
		and the value.
	*/
	Paginate(t PaginationType, value int) bool
	/*
		Filter creates a filter at this level given a function type and a list of variables with the
		same syntax as a function.
	*/
	Filter(t FunctionType, variables ...interface{}) bool
	/*
		Sort applies a sorting at this level.
	*/
	Sort(t OrderType, p Predicate) bool
	/*
		Aggregate sets an aggregation at this level.
	*/
	Aggregate(t AggregateType, v string, alias string) bool
	/*
		Count sets a count variable at this level, e.g.
		result : count(uid) given a "uid" as predicate and
		"result" as alias.
	*/
	Count(p Predicate, alias string) bool
	/*
		Variable sets a variable at this level.
		It either generates a value variable or an alias variable.
		If name is omitted so is the prefix for the variable. This
		can be useful for setting facet variables where name is omitted.
	*/
	Variable(name string, value string, isAlias bool) bool
}

Mod is the core for applying operations at certain predicate levels. There are two kind of 'mods', those which exist at root/edge level and those at field level. Paginate, Filter, Sort exists at root/edge level with the remaining existing at field level. This is an important distinction For Paginate, a path of "" applies the pagination at the top level (root) and given a single predicate P it applies it on the edge. For Variable, a path of "" applies the variable at the root field level, at the top level node.

type Mutate

type Mutate interface {
	Type() MutationType
	Cond() string
	// contains filtered or unexported methods
}

Mutate is the interface satisfied by all objects used in sending a json to the database. Any mutation sent to the database satisfies this interface.

func CreateCustomMutation

func CreateCustomMutation(obj interface{}, typ MutationType) Mutate

CreateCustomMutation allows you to create a mutation from an interface and not a DNode. This is useful alongside custom queries to set values, especially working with facets.

type MutationQuery

type MutationQuery struct {
	Values       []DNode
	Condition    string
	MutationType MutationType
}

func CreateMutations

func CreateMutations(typ MutationType, muts ...DNode) *MutationQuery

CreateMutations creates a list of mutations from a variadic list of Dnodes.

func (*MutationQuery) Cond

func (m *MutationQuery) Cond() string

func (*MutationQuery) SetCondition

func (m *MutationQuery) SetCondition(c string) *MutationQuery

func (*MutationQuery) Type

func (m *MutationQuery) Type() MutationType

type MutationType

type MutationType string

MutationType defines whether a mutation sets or deletes values.

const (
	MutateDelete MutationType = "delete"
	MutateSet    MutationType = "set"
)

type NewList

type NewList FieldList

NewList simply represents a list of fields where no copying is needed.

func (NewList) Add

func (f NewList) Add(fi Field) Fields

facet adds a field of type facet.

func (NewList) Get

func (f NewList) Get() []Field

func (NewList) Len

func (f NewList) Len() int

func (NewList) Select

func (f NewList) Select(names ...Predicate) Fields

func (NewList) Sub

func (f NewList) Sub(name Predicate, fl Fields) Fields

These lists do not need copying as they are never global.

type Node

type Node struct {
	Uid  UID      `json:"uid,omitempty" predicate:"uid,omitempty"`
	Type []string `json:"dgraph.type,omitempty" predicate:"dgraph.type,omitempty"`
}

The common node type that is inherited. This differs from the DNode which is an interface while node is an embedded struct containing basic dgraph properties.

func Uid

func Uid(u UID) Node

Uid simply returns a struct that can be used in 1-1 relations, i.e. map[key] = mulbase.Uid(uiD)

func (*Node) Fields

func (n *Node) Fields() Fields

func (*Node) GetType

func (n *Node) GetType() []string

func (*Node) MapValues

func (n *Node) MapValues() Mapper

func (*Node) Recurse

func (n *Node) Recurse(counter int) int

func (*Node) SetType

func (n *Node) SetType()

func (*Node) SetUID

func (n *Node) SetUID(uid UID)

func (*Node) UID

func (n *Node) UID() UID

func (*Node) Values

func (n *Node) Values() DNode

type Operation

type Operation func(m Mod)

Operation is a closure callback given a mod. Any operations called on this applies the given operation at the path.

type OrderType

type OrderType string
const (
	Ascending  OrderType = "orderasc"
	Descending OrderType = "orderdesc"
)

type Ordering

type Ordering struct {
	Type      OrderType
	Predicate Predicate
}

type PaginationType

type PaginationType string

PaginationType simply refers to a type of pagination.

const (
	CountFirst  PaginationType = "first"
	CountOffset PaginationType = "offset"
	CountAfter  PaginationType = "after"
)

type Predicate

type Predicate string

func (Predicate) String

func (s Predicate) String() string

Stringify this predicate.

type Querier

type Querier interface {
	//Query queries the database with a variable amount of interfaces to deserialize into.
	//That is, if you are performing two queries q and q1 you are expected to supply two values.
	Query(context.Context, Query, ...interface{}) error
	//mutate mutates the query and returns the response.
	Mutate(context.Context, Query) (*api.Response, error)
	//Discard the transaction. This is done automatically in DB but not in Txn.
	Discard(context.Context) error
	//Commit is the same as above except it commits the transaction.
	Commit(context.Context) error
}

Querier is an abstraction over DB/TXN. Also allows for testing.

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

Queries represents multiple queries at once.

func NewQueries

func NewQueries() *Queries

NewQueries returns a QueryList used for building multiple queries at once.

func (*Queries) NewQuery

func (q *Queries) NewQuery(f Fields) *GeneratedQuery

func (*Queries) Process

func (q *Queries) Process() (string, error)

Satisfy the Query interface.

type Query

type Query interface {
	//Process the query type in order to send to the database.
	Process() (string, error)
	// contains filtered or unexported methods
}

Query is the humus interface for a query. GeneratedQuery, Queries, StaticQuery all satisfy this interface and is used in generating all necessary information to send the query to the database.

type Result

type Result struct {
	Err error
	Res *api.Response
}

Result represents a result from an asynchronous operation.

type Saver

type Saver interface {
	Save() (DNode, error)
}

Saver allows you to implement a custom save method.

type SchemaList

type SchemaList map[Predicate]Field

SchemaList represents a schema.

type SingleMutation

type SingleMutation struct {
	Object       DNode
	MutationType MutationType
	//Used for upsert.
	Condition string
}

SingleMutation represents just that, one object mutated. interface{} is used over DNode as the structure of a mutation might change so a map[string]interface{} is needed for certain mutations.

func CreateMutation

func CreateMutation(obj DNode, typ MutationType) SingleMutation

CreateMutation creates a mutation object from the DNode. This can be used immediately as a value for Mutation. A simple syntax would be GetDB().Mutate(ctx, CreateMutation(node, MutateSet)) where node represents an arbitrary Node.

func (SingleMutation) Cond

func (s SingleMutation) Cond() string

func (SingleMutation) Type

func (s SingleMutation) Type() MutationType

func (SingleMutation) WithCond

func (s SingleMutation) WithCond(cond string) SingleMutation

type StaticQuery

type StaticQuery struct {
	Query string
	// contains filtered or unexported fields
}

StaticQuery represents a static query.

func NewStaticQuery

func NewStaticQuery(query string) StaticQuery

NewStaticQuery creates a formatted query. Use fmt.Sprintf as well as SetVar to supply parameters.

func (StaticQuery) Process

func (s StaticQuery) Process() (string, error)

Process the query in order to send to DGraph.

func (StaticQuery) QueryWithVars

func (s StaticQuery) QueryWithVars(vars map[string]string) StaticQuery

func (*StaticQuery) SetVar

func (s *StaticQuery) SetVar(key string, val interface{}) *StaticQuery

SetVar sets the variable in the GraphQL query map. Since it is a static query the type is expected to be supplied in the string part of the query and not here.

type Txn

type Txn struct {
	//Allows for safe storage in Queries.
	sync.Mutex
	//All queries performed by this transaction.
	Queries []interface{}
	// contains filtered or unexported fields
}

Txn is an abstraction over a dgraph transaction. In order to perform multiple queries & mutations use this. TODO: Should it be thread-safe? TODO: Do not keep a storage of previous queries and reuse GeneratedQuery with sync.Pool?

func (*Txn) Commit

func (t *Txn) Commit(ctx context.Context) error

Commit commits the transaction to the database.

func (*Txn) Discard

func (t *Txn) Discard(ctx context.Context) error

Discard discards the given transaction. Any further queries on this txn results in an error.

func (*Txn) Mutate

func (t *Txn) Mutate(ctx context.Context, q Mutate) (*api.Response, error)

Mutate runs a single mutation inside this transaction object.

func (*Txn) MutateAsync

func (t *Txn) MutateAsync(ctx context.Context, q Mutate) chan Result

MutateAsync runs a single mutation asynchronously inside this transaction.

func (*Txn) Query

func (t *Txn) Query(ctx context.Context, q Query, objs ...interface{}) error

Query executes the GraphQL+- query. If q is a mutation query the mutation objects are supplied in q and not in objs.

func (*Txn) QueryAsync

func (t *Txn) QueryAsync(ctx context.Context, q Query, objs ...interface{}) chan Result

QueryAsync runs the query asynchronous. In the result the error is returned.

func (*Txn) Upsert

func (t *Txn) Upsert(ctx context.Context, q Query, mutations ...Mutate) (*api.Response, error)

Upsert follows the new 1.1 api and performs an upsert. q is a nameless query. For now it is recommended to use a static query for all upserts. Cond is a condition of the form if (eq(len(a), 0) and so on. mutations is a list of mutations to perform.

type UID

type UID string

UID represents the primary UID class used in communication with DGraph. This is used in code generation and for type safety.

func ParseUid

func ParseUid(id int64) UID

ParseUid parses a uid from an int64.

func UIDVariable

func UIDVariable(variable string) UID

UidFromVariable returns the proper uid mapping for upserts, of the form uid(variable).

func (UID) Int

func (u UID) Int() int64

Int returns an int64 representation of the UID that is of the form 0xvalue. Returns -1 on error.

func (UID) IntString

func (u UID) IntString() string

IntString returns a string representation of the integer form of the uid u.

type Variable

type Variable string

Variable represents a value variable. This static type enforces a 'val' in the query generation in e.g. functions and filters. //TODO, not implemented yet.

Directories

Path Synopsis
examples
gen
packrd
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
parse
You can use the "packr clean" command to clean up this, and any other packr generated files.
You can use the "packr clean" command to clean up this, and any other packr generated files.

Jump to

Keyboard shortcuts

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