Skip to content

Commit 7169903

Browse files
Support for conditional upsert - added doQuery function (#63)
* Support for conditional upsert * Minor fixes * Removing the deprecated flag enterprise-feature * Updated examples
1 parent 0f08e71 commit 7169903

31 files changed

+526
-1799
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ before_install:
1111
- docker pull dgraph/dgraph:master
1212
- docker run -d --network dg --name zero dgraph/dgraph:master dgraph zero --my=zero:5080
1313
- sleep 30
14-
- docker run -d --network dg -p 9080:9080 --name alpha -v `pwd`/hmac-secret:/tmp/hmac-secret dgraph/dgraph:master dgraph alpha --acl_secret_file=/tmp/hmac-secret --bindall --enterprise_features --lru_mb 4096 --zero zero:5080 --my=alpha:7080
14+
- docker run -d --network dg -p 9080:9080 --name alpha -v `pwd`/hmac-secret:/tmp/hmac-secret dgraph/dgraph:master dgraph alpha --acl_secret_file=/tmp/hmac-secret --bindall --lru_mb 4096 --zero zero:5080 --my=alpha:7080
1515
- sleep 30
1616
- docker ps -a
1717
script:

examples/simple/index-pre-v7.6.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function createData(dgraphClient) {
3939

4040
// Create data.
4141
const p = {
42+
uid: "_:alice",
4243
name: "Alice",
4344
age: 26,
4445
married: true,
@@ -64,26 +65,25 @@ function createData(dgraphClient) {
6465
]
6566
};
6667

67-
let assigned;
68+
let response;
6869
let err;
6970

7071
// Run mutation.
7172
const mu = new dgraph.Mutation();
7273
mu.setSetJson(p);
7374
return txn.mutate(mu).then((res) => {
74-
assigned = res;
75+
response = res;
7576

7677
// Commit transaction.
7778
return txn.commit();
7879
}).then(() => {
7980
// Get uid of the outermost object (person named "Alice").
80-
// Assigned#getUidsMap() returns a map from blank node names to uids.
81-
// For a json mutation, blank node names "blank-0", "blank-1", ... are used
82-
// for all the created nodes.
83-
console.log(`Created person named "Alice" with uid = ${assigned.getUidsMap().get("blank-0")}\n`);
81+
// Response#getUidsMap() returns a map from blank node names to uids.
82+
// For a json mutation, blank node label is used for the name of the created nodes.
83+
console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
8484

8585
console.log("All created nodes (map from blank node names to uids):");
86-
assigned.getUidsMap().forEach((uid, key) => console.log(`${key}: ${uid}`));
86+
response.getUidsMap().forEach((uid, key) => console.log(`${key}: ${uid}`));
8787
console.log();
8888
}).catch((e) => {
8989
err = e;

examples/simple/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async function createData(dgraphClient) {
3939
try {
4040
// Create data.
4141
const p = {
42+
uid: "_:alice",
4243
name: "Alice",
4344
age: 26,
4445
married: true,
@@ -67,19 +68,18 @@ async function createData(dgraphClient) {
6768
// Run mutation.
6869
const mu = new dgraph.Mutation();
6970
mu.setSetJson(p);
70-
const assigned = await txn.mutate(mu);
71+
const response = await txn.mutate(mu);
7172

7273
// Commit transaction.
7374
await txn.commit();
7475

7576
// Get uid of the outermost object (person named "Alice").
76-
// Assigned#getUidsMap() returns a map from blank node names to uids.
77-
// For a json mutation, blank node names "blank-0", "blank-1", ... are used
78-
// for all the created nodes.
79-
console.log(`Created person named "Alice" with uid = ${assigned.getUidsMap().get("blank-0")}\n`);
77+
// Response#getUidsMap() returns a map from blank node names to uids.
78+
// For a json mutation, blank node label is used for the name of the created nodes.
79+
console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
8080

8181
console.log("All created nodes (map from blank node names to uids):");
82-
assigned.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
82+
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
8383
console.log();
8484
} finally {
8585
// Clean up. Calling this after txn.commit() is a no-op

examples/tls/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async function createData(dgraphClient) {
5151
try {
5252
// Create data.
5353
const p = {
54+
uid: "_:alice",
5455
name: "Alice",
5556
age: 26,
5657
married: true,
@@ -79,19 +80,18 @@ async function createData(dgraphClient) {
7980
// Run mutation.
8081
const mu = new dgraph.Mutation();
8182
mu.setSetJson(p);
82-
const assigned = await txn.mutate(mu);
83+
const response = await txn.mutate(mu);
8384

8485
// Commit transaction.
8586
await txn.commit();
8687

8788
// Get uid of the outermost object (person named "Alice").
88-
// Assigned#getUidsMap() returns a map from blank node names to uids.
89-
// For a json mutation, blank node names "blank-0", "blank-1", ... are used
90-
// for all the created nodes.
91-
console.log(`Created person named "Alice" with uid = ${assigned.getUidsMap().get("blank-0")}\n`);
89+
// Response#getUidsMap() returns a map from blank node names to uids.
90+
// For a json mutation, blank node label is used for the name of the created nodes.
91+
console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
9292

9393
console.log("All created nodes (map from blank node names to uids):");
94-
assigned.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
94+
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
9595
console.log();
9696
} finally {
9797
// Clean up. Calling this after txn.commit() is a no-op

generated/api_grpc_pb.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class DgraphClient extends grpc.Client {
3030
request: api_pb.Mutation,
3131
metadata: grpc.Metadata | null,
3232
options: grpc.CallOptions | null,
33-
callback: (err?: Error | null, res?: api_pb.Assigned) => void,
33+
callback: (err?: Error | null, res?: api_pb.Response) => void,
3434
): void;
3535

3636
public commitOrAbort(

generated/api_grpc_pb.js

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@
1616
// See the License for the specific language governing permissions and
1717
// limitations under the License.
1818
//
19+
// Style guide for Protocol Buffer 3.
20+
// Use PascalCase (camelCase with an initial capital) for message names – for example,
21+
// SongServerRequest. Use snake_case (underscore_separated_names) for field names – for
22+
// example, song_name.
23+
//
1924
'use strict';
2025
var grpc = require('grpc');
2126
var api_pb = require('./api_pb.js');
2227

23-
function serialize_api_Assigned(arg) {
24-
if (!(arg instanceof api_pb.Assigned)) {
25-
throw new Error('Expected argument of type api.Assigned');
26-
}
27-
return Buffer.from(arg.serializeBinary());
28-
}
29-
30-
function deserialize_api_Assigned(buffer_arg) {
31-
return api_pb.Assigned.deserializeBinary(new Uint8Array(buffer_arg));
32-
}
33-
3428
function serialize_api_Check(arg) {
3529
if (!(arg instanceof api_pb.Check)) {
3630
throw new Error('Expected argument of type api.Check');
@@ -53,17 +47,6 @@ function deserialize_api_LoginRequest(buffer_arg) {
5347
return api_pb.LoginRequest.deserializeBinary(new Uint8Array(buffer_arg));
5448
}
5549

56-
function serialize_api_Mutation(arg) {
57-
if (!(arg instanceof api_pb.Mutation)) {
58-
throw new Error('Expected argument of type api.Mutation');
59-
}
60-
return Buffer.from(arg.serializeBinary());
61-
}
62-
63-
function deserialize_api_Mutation(buffer_arg) {
64-
return api_pb.Mutation.deserializeBinary(new Uint8Array(buffer_arg));
65-
}
66-
6750
function serialize_api_Operation(arg) {
6851
if (!(arg instanceof api_pb.Operation)) {
6952
throw new Error('Expected argument of type api.Operation');
@@ -155,17 +138,6 @@ var DgraphService = exports.DgraphService = {
155138
responseSerialize: serialize_api_Response,
156139
responseDeserialize: deserialize_api_Response,
157140
},
158-
mutate: {
159-
path: '/api.Dgraph/Mutate',
160-
requestStream: false,
161-
responseStream: false,
162-
requestType: api_pb.Mutation,
163-
responseType: api_pb.Assigned,
164-
requestSerialize: serialize_api_Mutation,
165-
requestDeserialize: deserialize_api_Mutation,
166-
responseSerialize: serialize_api_Assigned,
167-
responseDeserialize: deserialize_api_Assigned,
168-
},
169141
alter: {
170142
path: '/api.Dgraph/Alter',
171143
requestStream: false,

0 commit comments

Comments
 (0)