Skip to content

Commit a7767cc

Browse files
authored
Merge pull request #123 from dgraph-io/rajas/add_example
Add dropOp mutation to example
2 parents e9e9bf5 + 917f0ac commit a7767cc

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

examples/simple/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ Number of people named "Alice": 1
7373
dob: '1980-02-01T17:30:00Z',
7474
friend: [ { name: 'Bob', age: 24 }, { name: 'Charlie', age: 29 } ],
7575
school: [ { name: 'Crown Public School' } ] }
76+
Number of people named "Alice": 0
77+
Created person named "Alice" with uid = 0x19
78+
79+
All created nodes (map from blank node names to uids):
80+
alice => 0x19
81+
dg.3973478125.10 => 0x16
82+
dg.3973478125.11 => 0x17
83+
dg.3973478125.12 => 0x18
84+
85+
Number of people named "Alice": 1
86+
{ uid: '0x19',
87+
name: 'Alice',
88+
age: 26,
89+
married: true,
90+
loc: { type: 'Point', coordinates: [ 1.1, 2 ] },
91+
dob: '1980-02-01T17:30:00Z',
92+
friend: [ { name: 'Bob', age: 24 }, { name: 'Charlie', age: 29 } ],
93+
school: [ { name: 'Crown Public School' } ] }
7694

7795
DONE!
7896
```

examples/simple/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ const grpc = require("grpc");
33

44
// Create a client stub.
55
function newClientStub() {
6-
return new dgraph.DgraphClientStub("localhost:9080", grpc.credentials.createInsecure());
6+
return new dgraph.DgraphClientStub("localhost:9080");
77
}
88

99
// Create a client.
1010
function newClient(clientStub) {
1111
return new dgraph.DgraphClient(clientStub);
1212
}
1313

14-
// Drop All - discard all data and start from a clean slate.
14+
// Drop All - discard all data, schema and start from a clean slate.
1515
async function dropAll(dgraphClient) {
1616
const op = new dgraph.Operation();
1717
op.setDropAll(true);
1818
await dgraphClient.alter(op);
1919
}
2020

21+
// Drop All Data, but keep the schema.
22+
async function dropData(dgraphClient) {
23+
const op = new dgraph.Operation();
24+
op.setDropOp(dgraph.Operation.DropOp.DATA);
25+
await dgraphClient.alter(op);
26+
}
27+
2128
// Set schema.
2229
async function setSchema(dgraphClient) {
2330
const schema = `
@@ -125,6 +132,10 @@ async function main() {
125132
await setSchema(dgraphClient);
126133
await createData(dgraphClient);
127134
await queryData(dgraphClient);
135+
await dropData(dgraphClient);
136+
await queryData(dgraphClient);
137+
await createData(dgraphClient);
138+
await queryData(dgraphClient);
128139

129140
// Close the client stub.
130141
dgraphClientStub.close();

0 commit comments

Comments
 (0)