Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
2f499c15
Commit
2f499c15
authored
8 years ago
by
MichaelJCompton
Browse files
Options
Downloads
Patches
Plain Diff
godoc updates
parent
ce06ecec
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
client/client.go
+3
-3
3 additions, 3 deletions
client/client.go
client/doc.go
+1
-1
1 addition, 1 deletion
client/doc.go
client/examples_test.go
+140
-11
140 additions, 11 deletions
client/examples_test.go
client/mutations.go
+5
-5
5 additions, 5 deletions
client/mutations.go
with
149 additions
and
20 deletions
client/client.go
+
3
−
3
View file @
2f499c15
...
@@ -92,7 +92,7 @@ func (req *Req) addMutation(e Edge, op opType) {
...
@@ -92,7 +92,7 @@ func (req *Req) addMutation(e Edge, op opType) {
}
}
// Set adds edge e to the set mutation of request req, thus scheduling the edge to be added to the graph when the request is run.
// Set adds edge e to the set mutation of request req, thus scheduling the edge to be added to the graph when the request is run.
// The edge must be syntatically valid: have a valid source (a Node), predicate and target (a Node or value), otherwise an error is returned.
// The edge must be synta
c
tically valid: have a valid source (a Node), predicate and target (a Node or value), otherwise an error is returned.
// The edge is not checked agaist the schema until the request is run --- so setting a UID edge to a value, for example, doesn't result in an
// The edge is not checked agaist the schema until the request is run --- so setting a UID edge to a value, for example, doesn't result in an
// error until the request is run.
// error until the request is run.
func
(
req
*
Req
)
Set
(
e
Edge
)
{
func
(
req
*
Req
)
Set
(
e
Edge
)
{
...
@@ -160,7 +160,7 @@ type nquadOp struct {
...
@@ -160,7 +160,7 @@ type nquadOp struct {
op
opType
op
opType
}
}
// Node represent
e
s a single node in the graph.
// Node represents a single node in the graph.
type
Node
struct
{
type
Node
struct
{
uid
uint64
uid
uint64
// We can do variables in mutations.
// We can do variables in mutations.
...
@@ -191,7 +191,7 @@ func (n *Node) ConnectTo(pred string, n1 Node) Edge {
...
@@ -191,7 +191,7 @@ func (n *Node) ConnectTo(pred string, n1 Node) Edge {
// Edge create an edge with source Node n and predicate pred, but without a target.
// Edge create an edge with source Node n and predicate pred, but without a target.
// The edge needs to be completed by calling Edge.ConnectTo() if the edge is a
// The edge needs to be completed by calling Edge.ConnectTo() if the edge is a
// UID edge, or one of the Edge.SetValue...() functions if the edge is of a scalar type.
// UID edge, or one of the Edge.SetValue...() functions if the edge is of a scalar type.
// The edge can't be commited to the store --- calling Req.Set() to add the edge to
// The edge can't be commit
t
ed to the store --- calling Req.Set() to add the edge to
// a request will result in an error --- until it is completed.
// a request will result in an error --- until it is completed.
func
(
n
*
Node
)
Edge
(
pred
string
)
Edge
{
func
(
n
*
Node
)
Edge
(
pred
string
)
Edge
{
e
:=
Edge
{}
e
:=
Edge
{}
...
...
This diff is collapsed.
Click to expand it.
client/doc.go
+
1
−
1
View file @
2f499c15
...
@@ -21,7 +21,7 @@ mutations can be run from the client. There are essentially two modes
...
@@ -21,7 +21,7 @@ mutations can be run from the client. There are essentially two modes
of client interaction:
of client interaction:
- Request based interaction mode where the user program builds requests
- Request based interaction mode where the user program builds requests
and rec
i
eves responses immediately after running, and
and rece
i
ves responses immediately after running, and
- Batch mode where clients submit many requests and let the client package
- Batch mode where clients submit many requests and let the client package
batch those requests to the server.
batch those requests to the server.
...
...
This diff is collapsed.
Click to expand it.
client/examples_test.go
+
140
−
11
View file @
2f499c15
...
@@ -87,7 +87,7 @@ func ExampleReq_Set() {
...
@@ -87,7 +87,7 @@ func ExampleReq_Set() {
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
}
}
func
Example
Req
_BatchSet
()
{
func
Example
Dgraph
_BatchSet
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
defer
conn
.
Close
()
defer
conn
.
Close
()
...
@@ -120,7 +120,7 @@ func ExampleReq_BatchSet() {
...
@@ -120,7 +120,7 @@ func ExampleReq_BatchSet() {
dgraphClient
.
BatchFlush
()
// Must be called to flush buffers after all mutations are added.
dgraphClient
.
BatchFlush
()
// Must be called to flush buffers after all mutations are added.
}
}
func
Example
Req
_AddFacet
()
{
func
Example
Edge
_AddFacet
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
defer
conn
.
Close
()
defer
conn
.
Close
()
...
@@ -159,8 +159,12 @@ func ExampleReq_AddFacet() {
...
@@ -159,8 +159,12 @@ func ExampleReq_AddFacet() {
e
.
AddFacet
(
"close"
,
"true"
)
e
.
AddFacet
(
"close"
,
"true"
)
req
.
Set
(
e
)
req
.
Set
(
e
)
req
.
AddSchemaFromString
(
`
name: string @index(exact) .
`
)
req
.
SetQuery
(
`{
req
.
SetQuery
(
`{
me(
id: person1
) {
me(
func: eq(name,"Steven Spielberg")
) {
name @facets
name @facets
friend @facets {
friend @facets {
name
name
...
@@ -194,10 +198,13 @@ func ExampleReq_AddSchemaFromString() {
...
@@ -194,10 +198,13 @@ func ExampleReq_AddSchemaFromString() {
req
:=
client
.
Req
{}
req
:=
client
.
Req
{}
// Add a schema mutation to the request
// Add a schema mutation to the request
req
.
AddSchemaFromString
(
`
err
=
req
.
AddSchemaFromString
(
`
name: string @index .
name: string @index
(term)
.
release_date: date @index .
release_date: date
Time
@index .
`
)
`
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error setting schema, %s"
,
err
)
}
// Query the changed schema
// Query the changed schema
req
.
SetQuery
(
`schema {}`
)
req
.
SetQuery
(
`schema {}`
)
...
@@ -236,6 +243,9 @@ func ExampleReq_SetQuery() {
...
@@ -236,6 +243,9 @@ func ExampleReq_SetQuery() {
req
.
Set
(
e
)
req
.
Set
(
e
)
req
.
AddSchemaFromString
(
`name: string @index(exact) .`
)
req
.
AddSchemaFromString
(
`name: string @index(exact) .`
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error setting schema, %s"
,
err
)
}
req
.
SetQuery
(
`{
req
.
SetQuery
(
`{
me(func: eq(name, "Alice")) {
me(func: eq(name, "Alice")) {
...
@@ -244,9 +254,13 @@ func ExampleReq_SetQuery() {
...
@@ -244,9 +254,13 @@ func ExampleReq_SetQuery() {
}
}
}`
)
}`
)
resp
,
err
:=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
resp
,
err
:=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error in getting response from server, %s"
,
err
)
}
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
}
}
func
ExampleReq_SetQueryWithVariables
()
{
func
ExampleReq_SetQueryWithVariables
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
...
@@ -293,7 +307,7 @@ func ExampleReq_SetQueryWithVariables() {
...
@@ -293,7 +307,7 @@ func ExampleReq_SetQueryWithVariables() {
func
Example
Req
_NodeUidVar
()
{
func
Example
Dgraph
_NodeUidVar
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
defer
conn
.
Close
()
defer
conn
.
Close
()
...
@@ -336,13 +350,15 @@ func ExampleReq_NodeUidVar() {
...
@@ -336,13 +350,15 @@ func ExampleReq_NodeUidVar() {
// Get a node for the variable a in the query above.
// Get a node for the variable a in the query above.
n
,
_
:=
dgraphClient
.
NodeUidVar
(
"a"
)
n
,
_
:=
dgraphClient
.
NodeUidVar
(
"a"
)
e
:
=
n
.
Edge
(
"falls.in"
)
e
=
n
.
Edge
(
"falls.in"
)
e
.
SetValueString
(
"Rabbit hole"
)
e
.
SetValueString
(
"Rabbit hole"
)
req
.
Set
(
e
)
req
.
Set
(
e
)
resp
,
err
:=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
resp
,
err
=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
x
.
Check
(
err
)
if
err
!=
nil
{
fmt
.
Printf
(
"Resp: %+v
\n
"
,
resp
)
log
.
Fatalf
(
"Error in getting response from server, %s"
,
err
)
}
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
// This is equivalent to the single query and mutation
// This is equivalent to the single query and mutation
...
@@ -360,3 +376,116 @@ func ExampleReq_NodeUidVar() {
...
@@ -360,3 +376,116 @@ func ExampleReq_NodeUidVar() {
// It's often easier to construct such things with client functions that
// It's often easier to construct such things with client functions that
// by manipulating raw strings.
// by manipulating raw strings.
}
}
func
ExampleEdge_SetValueBytes
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
defer
conn
.
Close
()
clientDir
,
err
:=
ioutil
.
TempDir
(
""
,
"client_"
)
x
.
Check
(
err
)
dgraphClient
:=
client
.
NewDgraphClient
([]
*
grpc
.
ClientConn
{
conn
},
client
.
DefaultOptions
,
clientDir
)
req
:=
client
.
Req
{}
alice
,
err
:=
dgraphClient
.
NodeBlank
(
"alice"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
e
:=
alice
.
Edge
(
"name"
)
e
.
SetValueString
(
"Alice"
)
req
.
Set
(
e
)
e
=
alice
.
Edge
(
"somestoredbytes"
)
err
=
e
.
SetValueBytes
([]
byte
(
`\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98`
))
x
.
Check
(
err
)
req
.
Set
(
e
)
req
.
AddSchemaFromString
(
`name: string @index(exact) .`
)
req
.
SetQuery
(
`{
q(func: eq(name, "Alice")) {
name
somestoredbytes
}
}`
)
resp
,
err
:=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error in getting response from server, %s"
,
err
)
}
fmt
.
Printf
(
"%+v
\n
"
,
proto
.
MarshalTextString
(
resp
))
}
func
ExampleUnmarshal
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9080"
,
grpc
.
WithInsecure
())
x
.
Checkf
(
err
,
"While trying to dial gRPC"
)
defer
conn
.
Close
()
clientDir
,
err
:=
ioutil
.
TempDir
(
""
,
"client_"
)
x
.
Check
(
err
)
dgraphClient
:=
client
.
NewDgraphClient
([]
*
grpc
.
ClientConn
{
conn
},
client
.
DefaultOptions
,
clientDir
)
req
:=
client
.
Req
{}
// A mutation as a string, see ExampleReq_NodeUidVar, ExampleReq_SetQuery,
// etc for examples of mutations using client functions.
req
.
SetQuery
(
`
mutation {
schema {
name: string @index .
}
set {
_:person1 <name> "Alex" .
_:person2 <name> "Beatie" .
_:person3 <name> "Chris" .
_:person1 <friend> _:person2 .
_:person1 <friend> _:person3 .
}
}
{
friends(func: eq(name, "Alex")) {
name
friend {
name
}
}
}`
)
// Run the request in the Dgraph server. The mutations are added, then
// the query is exectuted.
resp
,
err
:=
dgraphClient
.
Run
(
context
.
Background
(),
&
req
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error in getting response from server, %s"
,
err
)
}
// Unmarshal the response into a custom struct
// A type representing information in the graph.
type
person
struct
{
Name
string
`dgraph:"name"`
Friends
[]
person
`dgraph:"friend"`
}
// A helper type matching the query root.
type
friends
struct
{
Root
person
`dgraph:"friends"`
}
var
f
friends
err
=
client
.
Unmarshal
(
resp
.
N
,
&
f
)
if
err
!=
nil
{
log
.
Fatal
(
"Couldn't unmarshal response : "
,
err
)
}
fmt
.
Println
(
"Name : "
,
f
.
Root
.
Name
)
fmt
.
Print
(
"Friends : "
)
for
_
,
p
:=
range
f
.
Root
.
Friends
{
fmt
.
Print
(
p
.
Name
,
" "
)
}
fmt
.
Println
()
}
This diff is collapsed.
Click to expand it.
client/mutations.go
+
5
−
5
View file @
2f499c15
...
@@ -49,7 +49,7 @@ var (
...
@@ -49,7 +49,7 @@ var (
)
)
// BatchMutationOptions sets the clients batch mode to Pending number of buffers
// BatchMutationOptions sets the clients batch mode to Pending number of buffers
// each of Size. Running counters of number of rdfs proces
es
sed, total time and
// each of Size. Running counters of number of rdfs processed, total time and
// mutations per second are printed if PrintCounters is set true.
// mutations per second are printed if PrintCounters is set true.
// See Counter.
// See Counter.
type
BatchMutationOptions
struct
{
type
BatchMutationOptions
struct
{
...
@@ -383,7 +383,7 @@ func (d *Dgraph) BatchSet(e Edge) error {
...
@@ -383,7 +383,7 @@ func (d *Dgraph) BatchSet(e Edge) error {
}
}
// BatchDelete adds Edge e as a delete to the current batch mutation. Once added,
// BatchDelete adds Edge e as a delete to the current batch mutation. Once added,
// the client will apply the mutation to the
d
graph server when it is ready
// the client will apply the mutation to the
D
graph server when it is ready
// to flush its buffers. The edge will be added to one of the batches as
// to flush its buffers. The edge will be added to one of the batches as
// specified in d's BatchMutationOptions. If that batch fills, it eventually
// specified in d's BatchMutationOptions. If that batch fills, it eventually
// flushes. But there is no guarantee of delivery before BatchFlush() is
// flushes. But there is no guarantee of delivery before BatchFlush() is
...
@@ -397,7 +397,7 @@ func (d *Dgraph) BatchDelete(e Edge) error {
...
@@ -397,7 +397,7 @@ func (d *Dgraph) BatchDelete(e Edge) error {
return
nil
return
nil
}
}
// AddSchema adds the given schema mutat
at
ion to the batch of schema mutations.
// AddSchema adds the given schema mutation to the batch of schema mutations.
// If the schema mutation applies an index to a UID edge, or if it adds
// If the schema mutation applies an index to a UID edge, or if it adds
// reverse to a scalar edge, then the mutation is not added to the batch and an
// reverse to a scalar edge, then the mutation is not added to the batch and an
// error is returned. Once added, the client will apply the schema mutation when
// error is returned. Once added, the client will apply the schema mutation when
...
@@ -415,7 +415,7 @@ func (d *Dgraph) AddSchema(s protos.SchemaUpdate) error {
...
@@ -415,7 +415,7 @@ func (d *Dgraph) AddSchema(s protos.SchemaUpdate) error {
// edgename: uid @reverse .
// edgename: uid @reverse .
// edge2: string @index(exact) .
// edge2: string @index(exact) .
// etc.
// etc.
// to use the form "mut
u
ation { schema { ... }}" issue the mutation through
// to use the form "mutation { schema { ... }}" issue the mutation through
// SetQuery rather than as a batch.
// SetQuery rather than as a batch.
func
(
d
*
Dgraph
)
AddSchemaFromString
(
s
string
)
error
{
func
(
d
*
Dgraph
)
AddSchemaFromString
(
s
string
)
error
{
schemaUpdate
,
err
:=
schema
.
Parse
(
s
)
schemaUpdate
,
err
:=
schema
.
Parse
(
s
)
...
@@ -488,7 +488,7 @@ func (d *Dgraph) NodeUid(uid uint64) Node {
...
@@ -488,7 +488,7 @@ func (d *Dgraph) NodeUid(uid uint64) Node {
}
}
// NodeBlank creates or returns a Node given a string name for the blank node.
// NodeBlank creates or returns a Node given a string name for the blank node.
// Blank nodes do not exist as labelled nodes in
d
graph. Blank nodes are used
// Blank nodes do not exist as labelled nodes in
D
graph. Blank nodes are used
// as labels client side for loading and linking nodes correctly. If the
// as labels client side for loading and linking nodes correctly. If the
// label is new in this session a new UID is allocated and assigned to the
// label is new in this session a new UID is allocated and assigned to the
// label. If the label has already been assigned, the corresponding Node
// label. If the label has already been assigned, the corresponding Node
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment