Documentation ¶
Overview ¶
Package client is used to interact with a Dgraph server. Queries, mutations, and most other types of admin tasks can be run from the client.
Index ¶
- Variables
- func DeleteEdges(mu *api.Mutation, uid string, predicates ...string)
- type Dgraph
- type Txn
- func (txn *Txn) Commit(ctx context.Context) error
- func (txn *Txn) Discard(ctx context.Context) error
- func (txn *Txn) Mutate(ctx context.Context, mu *api.Mutation) (*api.Assigned, error)
- func (txn *Txn) Query(ctx context.Context, q string) (*api.Response, error)
- func (txn *Txn) QueryWithVars(ctx context.Context, q string, vars map[string]string) (*api.Response, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrFinished = errors.New("Transaction has already been committed or discarded")
)
Functions ¶
func DeleteEdges ¶ added in v0.9.2
DeleteEdges sets the edges corresponding to predicates on the node with the given uid for deletion. This helper function doesn't run the mutation on the server. It must be done by the user after the function returns.
Types ¶
type Dgraph ¶ added in v0.8.2
type Dgraph struct {
// contains filtered or unexported fields
}
Dgraph is a transaction aware client to a set of dgraph server instances.
func NewDgraphClient ¶ added in v0.8.2
func NewDgraphClient(clients ...api.DgraphClient) *Dgraph
NewDgraphClient creates a new Dgraph for interacting with the Dgraph store connected to in conns. The client can be backed by multiple connections (to the same server, or multiple servers in a cluster).
A single client is thread safe for sharing with multiple go routines.
type Txn ¶ added in v0.9.0
type Txn struct {
// contains filtered or unexported fields
}
Txn is a single atomic transaction.
A transaction lifecycle is as follows:
1. Created using NewTxn.
2. Various Query and Mutate calls made.
3. Commit or Discard used. If any mutations have been made, It's important that at least one of these methods is called to clean up resources. Discard is a no-op if Commit has already been called, so it's safe to defer a call to Discard immediately after NewTxn.
func (*Txn) Commit ¶ added in v0.9.0
Commit commits any mutations that have been made in the transaction. Once Commit has been called, the lifespan of the transaction is complete.
Errors could be returned for various reasons. Notably, ErrAborted could be returned if transactions that modify the same data are being run concurrently. It's up to the user to decide if they wish to retry. In this case, the user should create a new transaction.
func (*Txn) Discard ¶ added in v0.9.0
Discard cleans up the resources associated with an uncommitted transaction that contains mutations. It is a no-op on transactions that have already been committed or don't contain mutations. Therefore it is safe (and recommended) to call as a deferred function immediately after a new transaction is created.
In some cases, the transaction can't be discarded, e.g. the grpc connection is unavailable. In these cases, the server will eventually do the transaction clean up.
func (*Txn) Mutate ¶ added in v0.9.0
Mutate allows data stored on dgraph instances to be modified. The fields in api.Mutation come in pairs, set and delete. Mutations can either be encoded as JSON or as RDFs.
If CommitNow is set, then this call will result in the transaction being committed. In this case, an explicit call to Commit doesn't need to subsequently be made.
If the mutation fails, then the transaction is discarded and all future operations on it will fail.