Documentation ¶
Overview ¶
* Copyright (C) 2019 Dolan and Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
* Copyright (C) 2019 Dolan and Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
* Copyright (C) 2019 Dolan and Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
Index ¶
- Variables
- func GetNodeType(data interface{}) string
- func SetTypes(data interface{}) error
- 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) As(varName 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) 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) 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
func SetTypes ¶ added in v1.3.3
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 Deleter ¶ added in v0.5.0
type Deleter struct {
// contains filtered or unexported fields
}
func (*Deleter) All ¶ added in v0.5.0
All returns expands all predicates, with a depth parameter that specifies how deep should edges be expanded
func (*Deleter) Edge ¶ added in v0.6.0
Edge delete edges of a node of specified edge predicate, if no edgeUIDs specified, delete all edges
func (*Deleter) Filter ¶ added in v0.5.0
Filter defines a query filter, return predicates at the first depth
func (*Deleter) Node ¶ added in v0.5.0
Node deletes the first single root node from the query including edge nodes that may be specified on the query
func (*Deleter) Nodes ¶ added in v0.5.0
Nodes deletes all nodes matching the delete query including edge nodes that may be specified on the query
func (*Deleter) Query ¶ added in v0.5.0
Query defines the query portion other than the root function for deletion
func (*Deleter) RootFunc ¶ added in v0.5.1
RootFunc modifies the dgraph query root function, if not set, the default is "type(NodeType)"
type PagedResults ¶ added in v1.3.0
type PagedResults struct { Result json.RawMessage PageInfo []*PageInfo }
type ParamFormatter ¶ added in v1.0.0
type ParamFormatter interface {
FormatParams() []byte
}
ParamFormatter provides an interface for types to implement custom parameter formatter for query parameters
type Query ¶ added in v0.5.0
type Query struct {
// contains filtered or unexported fields
}
func (*Query) After ¶ added in v0.5.0
After uses default UID ordering to skip directly past a node specified by UID
func (*Query) All ¶ added in v0.5.0
All returns expands all predicates, with a depth parameter that specifies how deep should edges be expanded
func (*Query) As ¶ added in v1.3.0
As defines a query variable name https://dgraph.io/docs/query-language/#query-variables
func (*Query) Filter ¶ added in v0.5.0
Filter defines a query filter, return predicates at the first depth
func (*Query) Name ¶ added in v1.3.0
Name defines the query block name, which identifies the query results
func (*Query) Node ¶ added in v0.5.0
Node returns the first single node from the query, optional destination can be passed, otherwise bind to model
func (*Query) Nodes ¶ added in v0.5.0
Nodes returns all results from the query, optional destination can be passed, otherwise bind to model
func (*Query) NodesAndCount ¶ added in v1.3.0
NodesAndCount return paged nodes result with the total count of the query
func (*Query) RootFunc ¶ added in v0.5.1
RootFunc modifies the dgraph query root function, if not set, the default is "type(NodeType)"
type QueryBlock ¶ added in v1.3.0
type QueryBlock struct {
// contains filtered or unexported fields
}
func NewQueryBlock ¶ added in v1.3.0
func NewQueryBlock(queries ...*Query) *QueryBlock
NewQueryBlock returns a new empty query block
func (*QueryBlock) Add ¶ added in v1.3.0
func (q *QueryBlock) Add(query ...*Query) *QueryBlock
Add adds queries to the query block
func (*QueryBlock) Blocks ¶ added in v1.3.0
func (q *QueryBlock) Blocks(query ...*Query) *QueryBlock
Blocks set the query blocks
func (*QueryBlock) Scan ¶ added in v1.3.0
func (q *QueryBlock) Scan(dst interface{}) error
Scan unmarshals the query result into provided destination
func (*QueryBlock) String ¶ added in v1.3.0
func (q *QueryBlock) String() string
func (*QueryBlock) Vars ¶ added in v1.3.0
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 ¶ added in v1.1.1
type SchemaType interface {
SchemaType() string
}
SchemaType allows defining a custom type as a dgraph schema type
type TxnContext ¶ added in v1.0.0
type TxnContext struct {
// contains filtered or unexported fields
}
TxnContext is dgo transaction coupled with context
func NewReadOnlyTxn ¶ added in v1.0.0
func NewReadOnlyTxn(c *dgo.Dgraph) *TxnContext
NewReadOnlyTxn creates a new read only transaction
func NewReadOnlyTxnContext ¶ added in v1.0.0
func NewReadOnlyTxnContext(ctx context.Context, c *dgo.Dgraph) *TxnContext
NewReadOnlyTxnContext creates a new read only transaction coupled with a context
func NewTxn ¶ added in v1.0.0
func NewTxn(c *dgo.Dgraph) *TxnContext
NewTxn creates a new transaction
func NewTxnContext ¶ added in v1.0.0
func NewTxnContext(ctx context.Context, c *dgo.Dgraph) *TxnContext
NewTxnContext creates a new transaction coupled with a context
func (*TxnContext) BestEffort ¶ added in v1.0.0
func (t *TxnContext) BestEffort() *TxnContext
BestEffort enables best effort in read-only queries.
func (*TxnContext) Commit ¶ added in v1.0.0
func (t *TxnContext) Commit() error
Commit calls Commit on the dgo transaction.
func (*TxnContext) Context ¶ added in v1.0.0
func (t *TxnContext) Context() context.Context
Context returns the transaction context
func (*TxnContext) Create ¶ added in v1.0.0
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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
func (t *TxnContext) Delete(model interface{}, commitNow ...bool) *Deleter
Delete prepares a delete mutation using a query
func (*TxnContext) Discard ¶ added in v1.0.0
func (t *TxnContext) Discard() error
Discard calls Discard on the dgo transaction.
func (*TxnContext) Get ¶ added in v1.0.0
func (t *TxnContext) Get(model interface{}) *Query
Get prepares a query for a model
func (*TxnContext) Mutate ¶ added in v1.0.0
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.0
func (t *TxnContext) Query(query ...*Query) *QueryBlock
Query prepares a query with multiple query block
func (*TxnContext) Txn ¶ added in v1.0.0
func (t *TxnContext) Txn() *dgo.Txn
Txn returns the dgo transaction
func (*TxnContext) Update ¶ added in v1.0.0
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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
func (t *TxnContext) WithContext(ctx context.Context)
WithContext replaces the current transaction context
type TxnInterface ¶ added in v1.1.1
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 ¶ added in v1.0.0
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 ¶ added in v0.4.1
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 ¶ added in v1.0.0
func NewTypeSchema() *TypeSchema
NewTypeSchema returns a new TypeSchema with allocated Schema and Types
func (*TypeSchema) Marshal ¶ added in v1.0.0
func (t *TypeSchema) Marshal(parseType bool, models ...interface{})
Marshal marshals passed models into type and schema definitions
func (*TypeSchema) String ¶ added in v1.0.0
func (t *TypeSchema) String() string
type UID ¶ added in v1.0.0
type UID string
UID type allows passing uid's as query parameters
func (UID) FormatParams ¶ added in v1.0.0
FormatParams implements the ParamFormatter interface
type UIDs ¶ added in v1.0.0
type UIDs []string
UIDs type allows passing list of uid's as query parameters
func (UIDs) FormatParams ¶ added in v1.0.0
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