Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emicklei/dgraph-access
helper package on top of the official Go client for DGraph
https://github.com/emicklei/dgraph-access
client dgraph golang graph nquad rdf
Last synced: 21 days ago
JSON representation
helper package on top of the official Go client for DGraph
- Host: GitHub
- URL: https://github.com/emicklei/dgraph-access
- Owner: emicklei
- License: mit
- Created: 2019-03-19T21:22:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T02:11:29.000Z (over 1 year ago)
- Last Synced: 2024-10-11T20:29:56.960Z (about 1 month ago)
- Topics: client, dgraph, golang, graph, nquad, rdf
- Language: Go
- Size: 107 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dgraph-access
[![Build Status](https://travis-ci.org/emicklei/dgraph-access.png)](https://travis-ci.org/emicklei/dgraph-access)
[![Go Report Card](https://goreportcard.com/badge/github.com/emicklei/dgraph-access)](https://goreportcard.com/report/github.com/emicklei/dgraph-access)
[![GoDoc](https://godoc.org/github.com/emicklei/dgraph-access?status.svg)](https://pkg.go.dev/github.com/emicklei/dgraph-access?tab=doc)
[![codecov](https://codecov.io/gh/emicklei/dgraph-access/branch/master/graph/badge.svg)](https://codecov.io/gh/emicklei/dgraph-access)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 operationsThis repository also includes the [dggen tool](https://github.com/emicklei/dgraph-access/tree/master/cmd/dggen) 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](https://github.com/emicklei/dgraph-access/blob/master/examples).
See [documented code examples](https://godoc.org/github.com/emicklei/dgraph-access)
© 2019+, [ernestmicklei.com](http://ernestmicklei.com). MIT License. Contributions welcome.