Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Quirk is a Dgraph client utility that allows for easy node inserts and upserts using any struct or map

License

NotificationsYou must be signed in to change notification settings

damienfamed75/quirk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDocGo Report CardLicense

Quirk is a library used to seamlessly use upsert procedures in Dgraph without going through the hassle yourself.

Some Quick Notes about Quirk v2

With the recent update of Dgraph and dgo, Quirk has been versioned to v2.0.0 and is now using the new module taggithub.com/damienfamed75/quirk/v2. If you are using any Dgraph version below 1.1.0 and wish to still use quirk then please go ahead and download quirk v1.

Also Quirk will be updating to utilize further functionality added to dgo to optimize mutations as soon as possible. At the moment please enjoy Quirk v2 though in all its glory!

Install

To download Quirk v2, run this command to download the package.

go get github.com/damienfamed75/quirk/v2

If you wish to download Quirk v1, then run this command instead.

go get github.com/damienfamed75/quirk

Note if you are using Quirk v1 all imports in Go must not contain /v2

Using quirk

Here is a quick example of using a quirk client to insert a single node.

package mainimport ("context""fmt""github.com/damienfamed75/quirk/v2""github.com/dgraph-io/dgo/v2/protos/api""github.com/dgraph-io/dgo/v2""google.golang.org/grpc")funcmain() {// Create some data to insert in Dgraph.person:=struct {// These quirk tags are required.// It lets the quirk client know that this is the name// of the predicate in Dgraph.Namestring`quirk:"name"`SSNstring`quirk:"ssn,unique"`// Add unique if it should be upserted.Policystring`quirk:"policy,unique"`// As part of Dgraph 1.1.0 you can add types by just using the// "dgraph.type" tag using a string and Quirk will handle it correctly.Typestring`quirk:"dgraph.type"`    }{Name:"Damien",SSN:"123-12-1234",Policy:"ABCDAMIEN",Type:"Person",    }// Dial with GRPC to Dgraph as usual.conn,err:=grpc.Dial("127.0.0.1:9080",grpc.WithInsecure())iferr!=nil {fmt.Println(err)    }deferconn.Close()// Create the normal dgo client as usual.dg:=dgo.NewDgraphClient(api.NewDgraphClient(conn))// Add the schema to Dgraph.// Make sure to mark the unique predicates with the "@upsert" directive.err=dg.Alter(context.Background(),&api.Operation{Schema:`            name:   string @index(hash) .            ssn:    string @index(hash) @upsert .            policy: string @index(hash) @upsert .        `,    })iferr!=nil {fmt.Println(err)    }// Create a new quirk client.q:=quirk.NewClient()// Insert a single node. If we run this file multiple times you will// see that this node is never added twice.uids,err:=q.InsertNode(context.Background(),dg,&quirk.Operation{SetSingleStruct:&person,    })iferr!=nil {fmt.Println(err)    }// Print out the returned node and its uid.forn,u:=rangeuids {fmt.Printf("UIDMap: name[%s] uid[%s]\n",n,u)    }}

Contributing

Go ahead and create a PR or an issue. I'm always open for new contributions.


[8]ページ先頭

©2009-2025 Movatter.jp