dgraph

package
v1.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConfigured    = errors.New("graph db instances not configured. InitInstances() must be called to configure.")
	ErrInstanceNotFound = errors.New("graph db instance not found")
)

Functions

func GetTransaction

func GetTransaction(hostName string) (*dgo.Txn, error)

GetTransaction returns a new transaction for provided host.

If hostname is empty, transaction from default host will be returned.

Otherwise ErrInstanceNotFound error will be returned.

func InitInstances

func InitInstances(configs []Host) error

func NewClient

func NewClient(h Host) (*dgo.Dgraph, error)

NewClient returns a new dgraph client for provided configuration.

Types

type DGraphDAO

type DGraphDAO struct {
	HostName string
	// contains filtered or unexported fields
}

func GetDAO

func GetDAO(hostName string) (*DGraphDAO, error)

GetDAO returns a dao instance to access and manipulate graph data and schema.

If hostname is empty, default host will be used.

Otherwise ErrInstanceNotFound error will be returned.

func (*DGraphDAO) CreateSchema

func (dg *DGraphDAO) CreateSchema(ctx context.Context, schema string) error

CreateSchema sets the provided schema for the nodes data.

func (*DGraphDAO) DeleteData

func (dg *DGraphDAO) DeleteData(ctx context.Context, data []byte) error

DeleteData deletes the node or provided node attribute.

func (*DGraphDAO) DeleteDataTXN

func (dg *DGraphDAO) DeleteDataTXN(ctx context.Context, txn *dgo.Txn, data []byte) error

DeleteData deletes the node or provided node attribute.

The transacction must be committed or discarded.

func (*DGraphDAO) DeleteEdge

func (dg *DGraphDAO) DeleteEdge(ctx context.Context, uid string, predicates ...string) error

DeleteEdge deletes the edges for the mentioned node. predicate is the name of relationship between the node.

Ex. Persion1 `follows` Person2.

func (*DGraphDAO) DeleteEdgeTXN

func (dg *DGraphDAO) DeleteEdgeTXN(ctx context.Context, txn *dgo.Txn, uid string, predicates ...string) error

DeleteEdgeTXN deletes the edges for the mentioned node. predicate is the name of relationship between the node.

Ex. Persion1 `follows` Person2.

func (*DGraphDAO) DropAttr

func (dg *DGraphDAO) DropAttr(ctx context.Context, attr string) error

DropAttr deletes a specific attribute completely from data and the schema.

func (*DGraphDAO) DropData

func (dg *DGraphDAO) DropData(ctx context.Context) error

DropData deletes complete data but maintains the schema.

func (*DGraphDAO) DropSchema

func (dg *DGraphDAO) DropSchema(ctx context.Context) error

DropSchema deletes the current schema along with the data.

func (*DGraphDAO) GetData

func (dg *DGraphDAO) GetData(ctx context.Context, query string, vars map[string]string) ([]byte, error)

GetData returns the nodes matching to the provided query.

query variables can be provided in `vars` param. Safe to provide `nil` if no variables required.

The result is against the provided key in the query.

func (*DGraphDAO) SetData

func (dg *DGraphDAO) SetData(ctx context.Context, data []byte) error

SetData sets the provided data as a node. Can be used to create or update a node.

For update, the data must contain `uid` field.

func (*DGraphDAO) SetDataTXN

func (dg *DGraphDAO) SetDataTXN(ctx context.Context, txn *dgo.Txn, data []byte) error

SetData sets the provided data as a node. Can be used to create or update a node.

For update, the data must contain `uid` field.

The transacction must be committed or discarded.

type Host

type Host struct {
	Name       string `json:"hostName"`
	Server     string `json:"server"`
	Port       int    `json:"port"`
	IsDefault  bool   `json:"isDefault"`
	IsDisabled bool   `json:"IsDisabled"`
}

type Instance

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

func GetInstance

func GetInstance(hostName string) (*Instance, error)

GetInstance returns a preconfigured dgraph instance from cache. If not present, returns an error.

func NewInstance

func NewInstance(client *dgo.Dgraph, host Host) *Instance

NewInstance creates n new v2 instance of dgraph client. This instance can be saved in cache with host name as identifier for further operations.

Jump to

Keyboard shortcuts

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