Skip to content

emicklei/dgraph-access

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dgraph-access

Build Status Go Report Card GoDoc codecov

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" // this is for UID and Type propagation
    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+, ernestmicklei.com. MIT License. Contributions welcome.

About

helper package on top of the official Go client for DGraph

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages