A utility to make dealing with @google-cloud/datastore
keys little more pleasant.
var Datastore = require('@google-cloud/datastore');
var ds = new Datastore(/* init options */);
var KeyUtil = require('datastore-keyutil').KeyUtil;
var options = {
// boolean (default: false) - exposes instance as ds.keyUtil,
embed: true,
// function (default: throws BadKeyError with message) - function to call on invalid data.
errorFn: function(message, data) {
console.error(message, data);
throw new Error(message);
}
}
var ku = new KeyUtil(ds, options);
ds.query('kind')
.select('__key__')
.run()
.then(function (data) {
var entities = data[0];
var keysArray = ku.mapToKeys(entities);
var uidsArray = ku.mapToBase64UIDs(entities);
});
See here for an exhaustive list of KeyUtil functions.
To run the tests, you'll need to run a local Datastore emulator, from the Google Cloud SDK.
Then, run npm test
This library is still in beta, breaking changes may occur until v1.0.0 is reached. We use SemVer for versioning.
This project is licensed under the ISC License - see the LICENSE file for details.
This wouldn't be of any use without the NodeJS Google Cloud Datastore library.