Skip to content

Commit

Permalink
Fixes #48
Browse files Browse the repository at this point in the history
Fixes #234
  • Loading branch information
jmdobry committed Nov 15, 2016
1 parent 73a0764 commit ce8b714
Show file tree
Hide file tree
Showing 11 changed files with 1,380 additions and 1,624 deletions.
2,052 changes: 973 additions & 1,079 deletions datastore/concepts.js

Large diffs are not rendered by default.

67 changes: 33 additions & 34 deletions datastore/error.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
// Copyright 2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* Copyright 2016, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var Datastore = require('@google-cloud/datastore');

// Instantiate a datastore client
var datastore = Datastore();
const Datastore = require('@google-cloud/datastore');

// [START error]
function runQuery (cb) {
var query = datastore.createQuery(['Company']).start('badrequest');

datastore.runQuery(query, function (err, entities) {
// Check for an error
if (err) {
function runQuery () {
// Instantiates a client
const datastore = Datastore();

const query = datastore.createQuery(['Company']).start('badrequest');

return datastore.runQuery(query)
.then((results) => {
const entities = results[0];
console.log('Entities:');
entities.forEach((entity) => console.log(entity));
return entities;
})
.catch((err) => {
console.log(err.errors); // [...]
console.log(err.code); // 400
console.log(err.message); // "Bad Request"
Expand All @@ -38,21 +41,17 @@ function runQuery (cb) {

// For example, treat permission error like no entities were found
if (err.code === 403) {
return cb(null, []);
return [];
}

// Forward the error to the caller
return cb(err);
}

// We're good
return cb(null, entities);
});
return Promise.reject(err);
});
}
// [END error]

exports.runQuery = runQuery;

if (module === require.main) {
runQuery(console.log);
exports.runQuery();
}
12 changes: 6 additions & 6 deletions datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"scripts": {
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
"test": "mocha -R spec -t 1000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec -t 10000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"@google-cloud/datastore": "^0.1.1",
"async": "^2.0.1",
"yargs": "^5.0.0"
"@google-cloud/datastore": "^0.5.0",
"async": "^2.1.2",
"yargs": "^6.3.0"
},
"devDependencies": {
"mocha": "^3.0.2"
"mocha": "^3.1.2"
},
"engines": {
"node": ">=4.3.2"
Expand Down
Loading

0 comments on commit ce8b714

Please sign in to comment.