ndgom

package module
v0.0.0-...-7edbdc4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 11 Imported by: 0

README

ndgom GoDoc

WIP

ndgom builds on ndgo and aims to give orm like experience for dgraph graph db

Why

Coz it's fun.

Just look at the name alone. Let's break it down:

  •   g   - graph
  •  dg   - dgraph, the graph database
  •   go  - The Go Programming Language
  •  dgo  - dgo - the Dgraph Go client
  • ndgo  - ndgo - iterates on dgo adding low-abstraction abstractions
  •     m - as in map/mapper - adds mappings
  •    om - object mappings?
  •   gom - graph object mapping (as opposed to orm). Why not ogm? Because it would be too similar in name to dgogm and would add 2 characters instead of one to the name, that would be inefficient!
  •     m - magic! Initially, I planned ndgo to have an ndgo.Magic{} helper, but decided to keep it simple there - all the magic will happen here.
  • ndgom - all of the above.

Isn't it fun?

Note

Everything may or may not change ¯\_(ツ)_/¯

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExist = fmt.Errorf("object of requested type and uid does not exist")
)

Common Errors

View Source
var (
	// ErrUpsertUID happens when running upsert with wrong uid set in struct. Methods: Upd
	ErrUpsertUID = fmt.Errorf("uid of object must be set to uid(U)")
)

Stateless API Errors. Don't need to be handled in higher level APIs

View Source
var (
	ErrWrongInput = fmt.Errorf("input needs to be *ptr")
)

User Errors

Functions

func Debug

func Debug()

Debug enables logging of debug information, like ignored fields during parsing etc. Uses the default std logger

Types

type Admin

type Admin struct{}

Admin groups helpers with non common administrative uses, to keep API clean Usage: ndgom.Admin{}.

func (Admin) DropDB

func (Admin) DropDB(dg *dgo.Dgraph) error

DropDB does indeed nuke all DB data, returning it to a virgin state

func (Admin) MigrateSchema

func (Admin) MigrateSchema(dg *dgo.Dgraph, schema string) error

MigrateSchema runs schema migration

type Easy

type Easy struct{}

Easy groups Easy{}.API methods, the easiest one to use. Usage: ndgom.Easy{}. ...

func (Easy) Get

func (Easy) Get(result interface{}) (err error)

Get makes db query and populates result with found value or values. If result is struct, returns first result. If is slice, returns all found results.

func (Easy) GetByID

func (Easy) GetByID(result interface{}) (err error)

GetByID makes db query by uid and unmarshals result as object

func (Easy) Init

func (Easy) Init(d *dgo.Dgraph, timeout time.Duration)

Init initializes dgraph instance with a maximum txn timeout. If timeout is 0, default value of 60 seconds will be used.

func (Easy) New

func (Easy) New(obj interface{}) (err error)

New creates new node. Do not set UID. Type can be set, if node should have multiple, and must contain dgtype.

func (Easy) Upd

func (Easy) Upd(obj interface{}) (err error)

Upd updates node based on uid and changed fields, and unmarshals updated result into supplied obj

type Simple

type Simple struct{}

Simple groups Simple{}.API methods. Usage: ndgom.Simple{}. ...

func (Simple) Get

func (Simple) Get(txn *ndgo.Txn, predicate, value string, result interface{}) (err error)

Get makes db query and unmarshals results as array

func (Simple) GetByID

func (Simple) GetByID(txn *ndgo.Txn, uid string, result interface{}) (err error)

GetByID makes db query by uid and unmarshals result as object

func (Simple) GetOne

func (Simple) GetOne(txn *ndgo.Txn, predicate, value string, result interface{}) (err error)

GetOne makes db query and unmarshals first result as object

func (Simple) New

func (Simple) New(txn *ndgo.Txn, obj interface{}) (err error)

New creates new node. Do not set UID or Type. Can set Type if multiple needed.

func (Simple) Upd

func (Simple) Upd(txn *ndgo.Txn, obj interface{}) (err error)

Upd updates node based on uid and changed fields, and unmarshals updated result into supplied obj

type Stateless

type Stateless struct{}

Stateless groups stateless lower abstraction helpers. Does not use magic like reflection. Each helper does one db operation. Usage: ndgom.Stateless{}.

func (Stateless) Get

func (Stateless) Get(txn *ndgo.Txn, predicate, value, dgTypes string, result interface{}) (err error)

Get makes db query and unmarshals results as array

func (Stateless) GetByID

func (Stateless) GetByID(txn *ndgo.Txn, uid, dgTypes string, result interface{}) (err error)

GetByID makes db query by uid and unmarshals result as object

func (Stateless) GetOne

func (Stateless) GetOne(txn *ndgo.Txn, predicate, value, dgTypes string, result interface{}) (err error)

GetOne makes db query and unmarshals first result as object

func (Stateless) New

func (Stateless) New(txn *ndgo.Txn, obj interface{}) (uidMap map[string]string, err error)

New creates new node and returns uid map of created node(s)

func (Stateless) Upd

func (Stateless) Upd(txn *ndgo.Txn, uid, dgTypes string, obj interface{}) (err error)

Upd updates node of specified uid. Updated object should have set uid to `uid(U)`. Actual uid to update should be in the method. Doesn't result in complete updated object! (like Stateless{}.Get/New does)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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