Documentation ¶
Overview ¶
Package dgman is a schema manager for Dgraph using the Go Dgraph client (dgo), which manages Dgraph types, schema, and indexes from Go tags in struct definitions, allowing ORM-like convenience for developing Dgraph clients in Go.
Index ¶
- Variables
- func GetNodeType(data interface{}) string
- func SetTypes(data interface{}) error
- func SetUIDs(data interface{}, uids map[string]string) error
- type DeleteEdge
- type DeleteNode
- type DeleteParams
- type DeleteQuery
- 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) As(varName string) *Query
- func (q *Query) Cascade(predicates ...string) *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) Model(model interface{}) *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) RootFunc(rootFunc string) *Query
- func (q *Query) String() string
- 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) Delete(params ...*DeleteParams) error
- func (t *TxnContext) DeleteEdge(uid string, predicate string, uids ...string) error
- func (t *TxnContext) DeleteNode(uids ...string) error
- func (t *TxnContext) DeleteQuery(query *QueryBlock, params ...*DeleteParams) (DeleteQuery, error)
- func (t *TxnContext) Discard() error
- func (t *TxnContext) Get(model interface{}) *Query
- func (t *TxnContext) Mutate(data interface{}) ([]string, error)
- func (t *TxnContext) MutateBasic(data interface{}) ([]string, error)
- func (t *TxnContext) MutateOrGet(data interface{}, predicates ...string) ([]string, error)
- func (t *TxnContext) Query(query ...*Query) *QueryBlock
- func (t *TxnContext) SetCommitNow() *TxnContext
- func (t *TxnContext) Txn() *dgo.Txn
- func (t *TxnContext) Upsert(data interface{}, predicates ...string) ([]string, 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
func SetTypes ¶
func SetTypes(data interface{}) error
SetTypes recursively walks all structures in data and sets the value of the `dgraph.type` struct field. The type, in order of preference, is either the value of the `dgraph` struct tag on the `dgraph.type` struct field, or the struct name. Courtesy of @freb
Types ¶
type DeleteEdge ¶
type DeleteNode ¶
type DeleteNode struct { UID string Edges []DeleteEdge }
DeleteNode is a struct to build delete node n-quads
type DeleteParams ¶
type DeleteParams struct { Cond string Nodes []DeleteNode }
DeleteParams is a struct to past delete parameters
type DeleteQuery ¶
type DeleteQuery struct {
// contains filtered or unexported fields
}
func (*DeleteQuery) Scan ¶
func (d *DeleteQuery) Scan(dst ...interface{}) error
Scan will unmarshal the delete query result into the passed interface{}, if nothing is passed, it will be unmarshaled to the individual query models.
type PagedResults ¶
type PagedResults struct { Result stdjson.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 (*Query) All ¶
All returns expands all predicates, with a depth parameter that specifies how deep should edges be expanded
func (*Query) As ¶
As defines a query variable name https://dgraph.io/docs/query-language/#query-variables
func (*Query) Model ¶
Model defines the model definition to query by, and as a default query unmarshal destination
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 ¶
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 ¶
type QueryBlock struct {
// contains filtered or unexported fields
}
func NewQueryBlock ¶
func NewQueryBlock(queries ...*Query) *QueryBlock
NewQueryBlock returns a new empty query block
func (*QueryBlock) Add ¶
func (q *QueryBlock) Add(query ...*Query) *QueryBlock
Add adds queries to the query block
func (*QueryBlock) Blocks ¶
func (q *QueryBlock) Blocks(query ...*Query) *QueryBlock
Blocks set the query blocks
func (*QueryBlock) Scan ¶
func (q *QueryBlock) Scan(dst ...interface{}) error
Scan unmarshals the query result into provided destination, if none is passed, it will be unmarshaled to the individual query models.
func (*QueryBlock) String ¶
func (q *QueryBlock) String() string
func (*QueryBlock) Vars ¶
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) Delete ¶
func (t *TxnContext) Delete(params ...*DeleteParams) error
Delete will delete nodes using delete parameters, which will generate RDF n-quads for deleting
func (*TxnContext) DeleteEdge ¶
func (t *TxnContext) DeleteEdge(uid string, predicate string, uids ...string) error
DeleteEdge will delete an edge of a node by predicate, optionally you can pass which edge uids to delete, if none are passed, all edges of that predicate will be deleted
func (*TxnContext) DeleteNode ¶
func (t *TxnContext) DeleteNode(uids ...string) error
DeleteNode will delete a node(s) by its explicit uid
func (*TxnContext) DeleteQuery ¶
func (t *TxnContext) DeleteQuery(query *QueryBlock, params ...*DeleteParams) (DeleteQuery, error)
DeleteQuery will delete nodes using a query and delete parameters, which will generate RDF n-quads for deleting based on the 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{}) ([]string, error)
Mutate does a dgraph mutation, with recursive automatic uid injection (on empty uid fields), type injection (using the dgraph.type field), unique checking on fields (if applicable), and returns the created uids. It will return a UniqueError when unique checking fails on a field.
func (*TxnContext) MutateBasic ¶
func (t *TxnContext) MutateBasic(data interface{}) ([]string, error)
MutateBasic does a dgraph mutation like Mutate, but without any unique checking. This should be quite faster if there is no uniqueness requirement on the node type
func (*TxnContext) MutateOrGet ¶
func (t *TxnContext) MutateOrGet(data interface{}, predicates ...string) ([]string, error)
MutateOrGet does a dgraph mutation like Mutate, but instead of returning a UniqueError when a node already exists for a predicate value, it will get the existing node and inject it into the struct values. Optionally, a list of predicates can be passed to be specify predicates to be unique checked. A single node type can only have a single upsert predicate.
func (*TxnContext) Query ¶
func (t *TxnContext) Query(query ...*Query) *QueryBlock
Query prepares a query with multiple query block
func (*TxnContext) SetCommitNow ¶
func (t *TxnContext) SetCommitNow() *TxnContext
SetCommitNow specifies whether to commit as soon as a mutation is called,
i.e: set SetCommitNow: true in dgo.api.Mutation.
If this is called, a transaction can only be used for a single mutation.
func (*TxnContext) Upsert ¶
func (t *TxnContext) Upsert(data interface{}, predicates ...string) ([]string, error)
Upsert does a dgraph mutation like Mutate, but instead of returning a UniqueError when a node already exists for a predicate value, it will update the existing node and inject it into the struct values. Optionally, a list of predicates can be passed to be specify predicates to be unique checked. A single node type can only have a single upsert predicate.
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 SetCommitNow() *TxnContext BestEffort() *TxnContext Txn() *dgo.Txn WithContext(context.Context) Context() context.Context Mutate(data interface{}) ([]string, error) MutateOrGet(data interface{}, predicates ...string) ([]string, error) Upsert(data interface{}, predicates ...string) ([]string, error) Delete(params ...*DeleteParams) error DeleteQuery(query *QueryBlock, params ...*DeleteParams) (DeleteQuery, error) DeleteNode(uids ...string) error DeleteEdge(uid string, predicate string, uids ...string) error 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(parentType string, 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