Options
All
  • Public
  • Public/Protected
  • All
Menu

datastore-api

version license downloads

datastore-api

Simplified, more consistent API for Google Cloud Datastore.

Dstore implements a slightly more accessible version of the Google Cloud Datastore: Node.js Client

@google-cloud/datastore is a strange beast: The documentation is auto generated missing some core methods and completely shy of documenting any advanced concepts.

Also the typings are strange and overly broad.

Dstore tries to abstract away most surprises the datastore provides to you but als tries to stay as API compatible as possible to @google-cloud/datastore.

Main differences:

  • Everything asynchronous is Promise-based - no callbacks.
  • get always returns a single DstoreEntry.
  • getMulti always returns an Array.
  • set is called with (key, value) and always returns the complete Key of the entity being written.
  • allocateOneId returns a single numeric string encoded unique datastore id without the need of fancy unpacking.
  • runInTransaction allows you to provide a function to be executed inside an transaction without the need of passing around the transaction object. This is modelled after Python 2.7 ndb's @ndb.transactional feature. This is implemented via node's AsyncLocalStorage.
  • keySerialize is synchronous. 🦄

Find the full documentation here. In there also some of the idiosyncrasies of using the Datastore are explained.

See the API documentation for Details, Github for source.

Metrics

Datastore-API is instrumented with prom-client. Metrics are all prefixed with dstore_.

In an express based Application you can make them available like this:

import promClient from 'prom-client';

server.get('/metrics', async (req, res) => {
try {
res.set('Content-Type', promClient.register.contentType);
res.end(await promClient.register.metrics());
} catch (ex) {
res.status(500).end(ex);
}
});

See also

Generated using TypeDoc