Skip to content

๐Ÿ› ๏ธ Utility for dealing with @google-cloud/datastore Keys ๐Ÿ”‘

License

Notifications You must be signed in to change notification settings

beaulac/datastore-keyutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

42 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

datastore-keyutil

A utility to make dealing with @google-cloud/datastore keys little more pleasant.

Usage

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.

Running the tests

To run the tests, you'll need to run a local Datastore emulator, from the Google Cloud SDK.

Then, run npm test

Versioning

This library is still in beta, breaking changes may occur until v1.0.0 is reached. We use SemVer for versioning.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Acknowledgments

This wouldn't be of any use without the NodeJS Google Cloud Datastore library.

About

๐Ÿ› ๏ธ Utility for dealing with @google-cloud/datastore Keys ๐Ÿ”‘

Resources

License

Stars

Watchers

Forks

Packages

No packages published