6.0.2 • Published 8 months ago

datastore-api v6.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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. 🦄
  • Starting your code with the environment variable DEBUG='ds:api' allows you to trace API calls.

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.

Major issues

  • The Javascript-Datastore Bindings use nanosecond-Timestamp Information stored in the Datasore and rounds it to milliseconds. Python at least retains microseconds.
  • the old get_entity_group_version() / getEntityGroupVersion() API has been retired. You can still for key query { path: [key.path[0], {'kind': '__entity_group__', 'id': 1}]} to get a __version__ property. The reliability of this data on FireStore is unknown.
  • Googles Javascript API decided to use [Symbol(KEY)] to represent the Key in an entity. This results in all kinds of confusion when serializing to JSON, e.g. for caching. This library adds the property _keyStr which will be transparently used to regenerate [Symbol(KEY)] when needed.
  • Many functions are somewhat polymorphic where the shape of the return value depends on the function parameters, e.g. if the API was called with a key or a list of keys. You are encouraged to alvais provide a list of parameters instead a single parameter, e.g. get([key]) instead of get(key).
  • insert() and save() sometimes return the key being written and sometimes not. So you might or might not get some data in insertResponse?.[0].mutationResults?.[0]?.key?.path - urgs.
  • Google avoids BigInt. So key.id is (usually but not always) returned as a String but you have to provide a Number to the API.

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

child_process.execSync(`rm -Rf ./dsData`)
const port = await getPort({ port: 8081 })
emulator = new Emulator({ debug: false, port, storeOnDisk: true , clean: false, dataDir: './dsData'})

Then inspect datastore output with something like this:

/opt/homebrew/share/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator start --host=localhost --port=8081 --store_on_disk=True ./dsData & npx dsadmin --project=huwawi2
6.0.2

8 months ago

6.0.1

11 months ago

6.0.0

11 months ago

4.0.0

1 year ago

4.0.3

1 year ago

2.1.0

1 year ago

2.2.0

1 year ago

2.0.1

3 years ago

2.0.0

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago