Skip to content

Commit

Permalink
Support for conditional upsert - added doQuery function (#63)
Browse files Browse the repository at this point in the history
* Support for conditional upsert

* Minor fixes

* Removing the deprecated flag enterprise-feature

* Updated examples
  • Loading branch information
prashant-shahi committed Sep 3, 2019
1 parent 0f08e71 commit 7169903
Show file tree
Hide file tree
Showing 31 changed files with 526 additions and 1,799 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ before_install:
- docker pull dgraph/dgraph:master
- docker run -d --network dg --name zero dgraph/dgraph:master dgraph zero --my=zero:5080
- sleep 30
- 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
- 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
- sleep 30
- docker ps -a
script:
Expand Down
14 changes: 7 additions & 7 deletions examples/simple/index-pre-v7.6.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function createData(dgraphClient) {

// Create data.
const p = {
uid: "_:alice",
name: "Alice",
age: 26,
married: true,
Expand All @@ -64,26 +65,25 @@ function createData(dgraphClient) {
]
};

let assigned;
let response;
let err;

// Run mutation.
const mu = new dgraph.Mutation();
mu.setSetJson(p);
return txn.mutate(mu).then((res) => {
assigned = res;
response = res;

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

console.log("All created nodes (map from blank node names to uids):");
assigned.getUidsMap().forEach((uid, key) => console.log(`${key}: ${uid}`));
response.getUidsMap().forEach((uid, key) => console.log(`${key}: ${uid}`));
console.log();
}).catch((e) => {
err = e;
Expand Down
12 changes: 6 additions & 6 deletions examples/simple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function createData(dgraphClient) {
try {
// Create data.
const p = {
uid: "_:alice",
name: "Alice",
age: 26,
married: true,
Expand Down Expand Up @@ -67,19 +68,18 @@ async function createData(dgraphClient) {
// Run mutation.
const mu = new dgraph.Mutation();
mu.setSetJson(p);
const assigned = await txn.mutate(mu);
const response = await txn.mutate(mu);

// Commit transaction.
await txn.commit();

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

console.log("All created nodes (map from blank node names to uids):");
assigned.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
console.log();
} finally {
// Clean up. Calling this after txn.commit() is a no-op
Expand Down
12 changes: 6 additions & 6 deletions examples/tls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function createData(dgraphClient) {
try {
// Create data.
const p = {
uid: "_:alice",
name: "Alice",
age: 26,
married: true,
Expand Down Expand Up @@ -79,19 +80,18 @@ async function createData(dgraphClient) {
// Run mutation.
const mu = new dgraph.Mutation();
mu.setSetJson(p);
const assigned = await txn.mutate(mu);
const response = await txn.mutate(mu);

// Commit transaction.
await txn.commit();

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

console.log("All created nodes (map from blank node names to uids):");
assigned.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
console.log();
} finally {
// Clean up. Calling this after txn.commit() is a no-op
Expand Down
2 changes: 1 addition & 1 deletion generated/api_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DgraphClient extends grpc.Client {
request: api_pb.Mutation,
metadata: grpc.Metadata | null,
options: grpc.CallOptions | null,
callback: (err?: Error | null, res?: api_pb.Assigned) => void,
callback: (err?: Error | null, res?: api_pb.Response) => void,
): void;

public commitOrAbort(
Expand Down
38 changes: 5 additions & 33 deletions generated/api_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Style guide for Protocol Buffer 3.
// Use PascalCase (camelCase with an initial capital) for message names – for example,
// SongServerRequest. Use snake_case (underscore_separated_names) for field names – for
// example, song_name.
//
'use strict';
var grpc = require('grpc');
var api_pb = require('./api_pb.js');

function serialize_api_Assigned(arg) {
if (!(arg instanceof api_pb.Assigned)) {
throw new Error('Expected argument of type api.Assigned');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_api_Assigned(buffer_arg) {
return api_pb.Assigned.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_api_Check(arg) {
if (!(arg instanceof api_pb.Check)) {
throw new Error('Expected argument of type api.Check');
Expand All @@ -53,17 +47,6 @@ function deserialize_api_LoginRequest(buffer_arg) {
return api_pb.LoginRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_api_Mutation(arg) {
if (!(arg instanceof api_pb.Mutation)) {
throw new Error('Expected argument of type api.Mutation');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_api_Mutation(buffer_arg) {
return api_pb.Mutation.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_api_Operation(arg) {
if (!(arg instanceof api_pb.Operation)) {
throw new Error('Expected argument of type api.Operation');
Expand Down Expand Up @@ -155,17 +138,6 @@ var DgraphService = exports.DgraphService = {
responseSerialize: serialize_api_Response,
responseDeserialize: deserialize_api_Response,
},
mutate: {
path: '/api.Dgraph/Mutate',
requestStream: false,
responseStream: false,
requestType: api_pb.Mutation,
responseType: api_pb.Assigned,
requestSerialize: serialize_api_Mutation,
requestDeserialize: deserialize_api_Mutation,
responseSerialize: serialize_api_Assigned,
responseDeserialize: deserialize_api_Assigned,
},
alter: {
path: '/api.Dgraph/Alter',
requestStream: false,
Expand Down
Loading

0 comments on commit 7169903

Please sign in to comment.