Categorygithub.com/emicklei/dgraph-access
modulepackage
1.0.0-rc2
Repository: https://github.com/emicklei/dgraph-access.git
Documentation: pkg.go.dev

# README

dgraph-access

Build Status Go Report Card GoDoc

This is a helper package to work with github.com/dgraph-io/dgo (v2), a Go client for accessing a DGraph cluster. See the examples folder for complete programs.

status

This package is under development (see commits); the API and scope may change before a v1.0.0 release.

motivation

This package was created to reduce the boilerplate code required to use the raw dgraph Go client.

features

dgraph-access adds the following features to the standard Go client:

  • type UID and NQuad to create RDF triples w/o facets
  • type Node to encapsulate an uid and graph.type for your own entities
  • type DgraphAccess to handle transactions, JSON marshalling and populating entities
  • type Mutation to encapsulate a dgraph mutations that contains a list of RDF triples (NQuad values)
  • UpsertNode, CreateNode, CreateEdge, RunQuery, FindEquals model common dgraph operations
  • DgraphAccess can trace the queries, mutations and responses for debugging
  • DgraphAccess also provides a Service interface for convenient use of the operations

This repository also includes the dggen tool that takes a dgraph schema to generate Go types from Dgraph types.

usage

import (
    dga "github.com/emicklei/dgraph-access"
)

quick look

d := dga.NewDGraphAccess(yourDgraphClient).ForReadWrite()    
s := d.Service()
err := s.Alterschema(`name: string @index(exact) .`)
type Vegetable struct {
    dga.Node `json:",inline"
    Name string
    Color string
}
v1 := &Vegetable{Name:"Carrot"}
err = s.CreateNode(v1)

v2 := &Vegetable{Name:"Beet"}
err = s.CreateEdge(v1,"similarTo",v2)

v3 := new(Vegetable)
err := s.FindEquals(v3,"name","Carrot")    

v2.Color = "darkred"
s.UpsertNode(v2,"name","Beet")

examples

See examples.

See documented code examples

© 2019-2020, ernestmicklei.com. MIT License. Contributions welcome.

# Functions

BlankNQuad returns an NQuad value with a Blank UID subject.
BlankUID returns an UID with an undefined uid and a local name only valid for one write transaction.
IntegerUID returns an UID using the integer value.
No description provided by the author
NewDGraphAccess returns a new DGraphAccess using a client.
NewUID returns an UID that is printed as is.
No description provided by the author
StringUID returns an UID using a string value for uid.

# Constants

DateTimeFormat is the format used by Dgraph for facet values of type dateTime.
DgraphType is a reserved predicate name to refer to a type definition.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
see https://docs.dgraph.io/mutations/#language-and-rdf-types.
RDFString is a RDF type.
Star is used to model any predicate or any object in an NQuad.

# Variables

ErrNoClient is a DGraphAccess state error.
ErrNoContext is a DGraphAccess state error.
ErrNoTransaction is a DGraphAccess state error.
ErrUnmarshalQueryResult is returned when the result of a query cannot be unmarshalled from JSON.

# Structs

AlterSchema represents a Dgraph operation.
CreateEdge represents a Dgraph operation.
CreateNode models the operation to (conditionally) create a Dgraph node.
DGraphAccess is a decorator for a dgo.Client that holds a Context and Transaction to perform queries and mutations.
FindEquals populates the result with the result of matching a predicate with a value.
Mutation represents an action with multiple RDF Triples represented by NQuad values.
Node is an abstract type that encapsulates a Dgraph identity (uid) and type (dgraph.type) Node can be used to embed in your own entity type, e.g.: type Person struct { dga.Node `json:",inline"` Name string `json:"name"` }.
NQuad represents an RDF S P O pair.
RunQuery executes the raw query and populates the result with the data found using a given key.
Service is the API to use the operation types with DGraphAccess.
UID represents a DGraph uid which can be expressed using an integer,string or undefined value.
UpsertNode models the operation to insert (create) or update a Dgraph node.

# Interfaces

DGraphTransaction exists for testing.
HasUID is used in CreateNode to set the assigned UID to a typed value.
Operation is for dispatching commands using a DGraphAccess.

# Type aliases

RDFDatatype is to set the StorageType of an NQuad.