Documentation
¶
Index ¶
- Variables
- func GetNodeType(data interface{}) string
- func Node(jsonData []byte, model interface{}) error
- func Nodes(jsonData []byte, model interface{}) error
- type Block
- type Deleter
- func (d *Deleter) After(uid string) *Deleter
- func (d *Deleter) All(depthParam ...int) *Deleter
- func (d *Deleter) Edge(uid, edgePredicate string, edgeUIDs ...string) error
- func (d *Deleter) Filter(filter string, params ...interface{}) *Deleter
- func (d *Deleter) First(n int) *Deleter
- func (d *Deleter) Node() (uids []string, err error)
- func (d *Deleter) Nodes() (uids []string, err error)
- func (d *Deleter) Offset(n int) *Deleter
- func (d *Deleter) OrderAsc(clause string) *Deleter
- func (d *Deleter) OrderDesc(clause string) *Deleter
- func (d *Deleter) Query(query string, params ...interface{}) *Deleter
- func (d *Deleter) RootFunc(rootFunc string) *Deleter
- func (d *Deleter) String() string
- func (d *Deleter) UID(uid string) *Deleter
- func (d *Deleter) Vars(funcDef string, vars map[string]string) *Deleter
- type PageInfo
- type PagedResults
- type ParamFormatter
- type Query
- func (q *Query) After(uid string) *Query
- func (q *Query) All(depthParam ...int) *Query
- func (q *Query) AppendFilter(filter string, connect string, params ...interface{}) *Query
- func (q *Query) As(varName string) *Query
- func (q *Query) Block(b *Block) *Query
- func (q *Query) Filter(filter string, params ...interface{}) *Query
- func (q *Query) First(n int) *Query
- func (q *Query) GroupBy(predicate string) *Query
- func (q *Query) Name(queryName string) *Query
- func (q *Query) Node(dst ...interface{}) (err error)
- func (q *Query) Nodes(dst ...interface{}) error
- func (q *Query) NodesAndCount() (count int, err error)
- func (q *Query) Offset(n int) *Query
- func (q *Query) OrderAsc(clause string) *Query
- func (q *Query) OrderDesc(clause string) *Query
- func (q *Query) Query(query string, params ...interface{}) *Query
- func (q *Query) Recurse(depth int) *Query
- func (q *Query) RootFunc(rootFunc string) *Query
- func (q *Query) String() string
- func (q *Query) ToBlock() *Block
- func (q *Query) Type(model interface{}) *Query
- func (q *Query) UID(uid string) *Query
- func (q *Query) Var() *Query
- func (q *Query) Vars(funcDef string, vars map[string]string) *Query
- type QueryBlock
- type Schema
- type SchemaMap
- type SchemaType
- type TxnContext
- func (t *TxnContext) BestEffort() *TxnContext
- func (t *TxnContext) Commit() error
- func (t *TxnContext) Context() context.Context
- func (t *TxnContext) Create(data interface{}, commitNow ...bool) error
- func (t *TxnContext) CreateOrGet(data interface{}, predicate string, commitNow ...bool) error
- func (t *TxnContext) Delete(model interface{}, commitNow ...bool) *Deleter
- func (t *TxnContext) Discard() error
- func (t *TxnContext) Get(model interface{}) *Query
- func (t *TxnContext) Mutate(data interface{}, commitNow ...bool) error
- func (t *TxnContext) Query(query ...*Query) *QueryBlock
- func (t *TxnContext) Txn() *dgo.Txn
- func (t *TxnContext) Update(data interface{}, commitNow ...bool) error
- func (t *TxnContext) Upsert(data interface{}, predicate string, commitNow ...bool) error
- func (t *TxnContext) WithContext(ctx context.Context)
- type TxnInterface
- type TypeMap
- type TypeSchema
- type UID
- type UIDs
- type UniqueError
Constants ¶
This section is empty.
Variables ¶
var (
ErrNodeNotFound = errors.New("node not found")
)
Functions ¶
func GetNodeType ¶
func GetNodeType(data interface{}) string
GetNodeType gets node type from the struct name, or "dgraph" tag in the "dgraph.type" predicate/json tag
Types ¶
type Deleter ¶
type Deleter struct {
// contains filtered or unexported fields
}
func (*Deleter) All ¶
All returns expands all predicates, with a depth parameter that specifies how deep should edges be expanded
func (*Deleter) Edge ¶
Edge delete edges of a node of specified edge predicate, if no edgeUIDs specified, delete all edges
func (*Deleter) Node ¶
Node deletes the first single root node from the query including edge nodes that may be specified on the query
func (*Deleter) Nodes ¶
Nodes deletes all nodes matching the delete query including edge nodes that may be specified on the query
func (*Deleter) RootFunc ¶
RootFunc modifies the dgraph query root function, if not set, the default is "type(NodeType)"
type PagedResults ¶ added in v1.3.2
type PagedResults struct {
Result json.RawMessage
PageInfo []*PageInfo
}
type ParamFormatter ¶
type ParamFormatter interface {
FormatParams() []byte
}
ParamFormatter provides an interface for types to implement custom parameter formatter for query parameters
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func NewQueryBlock ¶ added in v1.3.2
func NewQueryBlock() *Query
NewQueryBlock returns a new empty query block
func (*Query) All ¶
All returns expands all predicates, with a depth parameter that specifies how deep should edges be expanded
func (*Query) AppendFilter ¶
func (*Query) As ¶ added in v1.3.2
As defines a query variable name https://dgraph.io/docs/query-language/#query-variables
func (*Query) Name ¶ added in v1.3.2
Name defines the query block name, which identifies the query results
func (*Query) Node ¶
Node returns the first single node from the query, optional destination can be passed, otherwise bind to model
func (*Query) Nodes ¶
Nodes returns all results from the query, optional destination can be passed, otherwise bind to model
func (*Query) NodesAndCount ¶ added in v1.3.2
NodesAndCount return paged nodes result with the total count of the query
func (*Query) RootFunc ¶
RootFunc modifies the dgraph query root function, if not set, the default is "type(NodeType)"
type QueryBlock ¶ added in v1.3.2
type QueryBlock struct {
// contains filtered or unexported fields
}
func (*QueryBlock) Add ¶ added in v1.3.2
func (q *QueryBlock) Add(query *Query) *QueryBlock
Add adds a query to the query block
func (*QueryBlock) Blocks ¶ added in v1.3.2
func (q *QueryBlock) Blocks(query ...*Query) *QueryBlock
Blocks set the query blocks
func (*QueryBlock) Scan ¶ added in v1.3.2
func (q *QueryBlock) Scan(dst interface{}) error
Scan unmarshals the query result into provided destination
func (*QueryBlock) String ¶ added in v1.3.2
func (q *QueryBlock) String() string
func (*QueryBlock) Vars ¶ added in v1.3.2
func (q *QueryBlock) Vars(funcDef string, vars map[string]string) *QueryBlock
Vars specify the GraphQL variables to be passed on the query, by specifying the function definition of vars, and variable map. Example funcDef: getUserByEmail($email: string)
type Schema ¶
type SchemaType ¶
type SchemaType interface {
SchemaType() string
}
SchemaType allows defining a custom type as a dgraph schema type
type TxnContext ¶
type TxnContext struct {
// contains filtered or unexported fields
}
TxnContext is dgo transaction coupled with context
func NewReadOnlyTxn ¶
func NewReadOnlyTxn(c *dgo.Dgraph) *TxnContext
NewReadOnlyTxn creates a new read only transaction
func NewReadOnlyTxnContext ¶
func NewReadOnlyTxnContext(ctx context.Context, c *dgo.Dgraph) *TxnContext
NewReadOnlyTxnContext creates a new read only transaction coupled with a context
func NewTxnContext ¶
func NewTxnContext(ctx context.Context, c *dgo.Dgraph) *TxnContext
NewTxnContext creates a new transaction coupled with a context
func (*TxnContext) BestEffort ¶
func (t *TxnContext) BestEffort() *TxnContext
BestEffort enables best effort in read-only queries.
func (*TxnContext) Commit ¶
func (t *TxnContext) Commit() error
Commit calls Commit on the dgo transaction.
func (*TxnContext) Context ¶
func (t *TxnContext) Context() context.Context
Context returns the transaction context
func (*TxnContext) Create ¶
func (t *TxnContext) Create(data interface{}, commitNow ...bool) error
Create create node(s) with field unique checking, similar to Mutate, will inject node type from the Struct name
func (*TxnContext) CreateOrGet ¶
func (t *TxnContext) CreateOrGet(data interface{}, predicate string, commitNow ...bool) error
CreateOrGet will create a node or if a node with a value from the passed predicate exists, return the node
func (*TxnContext) Delete ¶
func (t *TxnContext) Delete(model interface{}, commitNow ...bool) *Deleter
Delete prepares a delete mutation using a query
func (*TxnContext) Discard ¶
func (t *TxnContext) Discard() error
Discard calls Discard on the dgo transaction.
func (*TxnContext) Get ¶
func (t *TxnContext) Get(model interface{}) *Query
Get prepares a query for a model
func (*TxnContext) Mutate ¶
func (t *TxnContext) Mutate(data interface{}, commitNow ...bool) error
Mutate is a shortcut to create mutations from data to be marshalled into JSON, it will inject the node type from the Struct name
func (*TxnContext) Query ¶ added in v1.3.2
func (t *TxnContext) Query(query ...*Query) *QueryBlock
Query prepares a query with multiple query block
func (*TxnContext) Update ¶
func (t *TxnContext) Update(data interface{}, commitNow ...bool) error
Update updates a node by their UID with field unique checking, similar to Mutate, will inject node type from the Struct name
func (*TxnContext) Upsert ¶
func (t *TxnContext) Upsert(data interface{}, predicate string, commitNow ...bool) error
Upsert will update a node when a value from the passed predicate (with the node type) exists, otherwise insert the node. On all conditions, unique checking holds on the node type on other unique fields.
func (*TxnContext) WithContext ¶
func (t *TxnContext) WithContext(ctx context.Context)
WithContext replaces the current transaction context
type TxnInterface ¶
type TxnInterface interface {
Commit() error
Discard() error
BestEffort() *TxnContext
Txn() *dgo.Txn
WithContext(context.Context)
Context() context.Context
Mutate(data interface{}, commitNow ...bool) error
Create(data interface{}, commitNow ...bool) error
Update(data interface{}, commitNow ...bool) error
Upsert(data interface{}, predicate string, commitNow ...bool) error
CreateOrGet(data interface{}, predicate string, commitNow ...bool) error
Delete(model interface{}, commitNow ...bool) *Deleter
Get(model interface{}) *Query
}
TxnInterface provides interface for dgman.TxnContext
type TypeSchema ¶
func CreateSchema ¶
func CreateSchema(c *dgo.Dgraph, models ...interface{}) (*TypeSchema, error)
CreateSchema generate indexes, schema, and types from struct models, returns the created schema map and types, does not update duplicate/conflict predicates.
func MutateSchema ¶
func MutateSchema(c *dgo.Dgraph, models ...interface{}) (*TypeSchema, error)
MutateSchema generate indexes and schema from struct models, attempt updates for type, schema, and indexes.
func NewTypeSchema ¶
func NewTypeSchema() *TypeSchema
NewTypeSchema returns a new TypeSchema with allocated Schema and Types
func (*TypeSchema) Marshal ¶
func (t *TypeSchema) Marshal(parseType bool, models ...interface{})
Marshal marshals passed models into type and schema definitions
func (*TypeSchema) String ¶
func (t *TypeSchema) String() string
type UID ¶
type UID string
UID type allows passing uid's as query parameters
func (UID) FormatParams ¶
FormatParams implements the ParamFormatter interface
type UIDs ¶
type UIDs []string
UIDs type allows passing list of uid's as query parameters
func (UIDs) FormatParams ¶
FormatParams implements the ParamFormatter interface
type UniqueError ¶
UniqueError returns the field and value that failed the unique node check
func (*UniqueError) Error ¶
func (u *UniqueError) Error() string