NodeJS/Typescript Driver that makes using google datastore simple
Last updated a year ago by manojclsdkumar .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install google-datastore-driver 
SYNC missed versions from official npm registry.

Datastore Driver

Standalone Config:

Import config.service.ts, instantiate the class. The constructor takes in one argument the location of a .env file like:

PROJECT_ID = <cloud datastore project id>
DATASTOREKEY = <path to cloud datastore credential json file>
DATASTORE_NAMESPACE = <datastore namespace>

Alternatively, pass in a JSON object with the above keys and values into the second argument of the config class like:

export interface jsonConfig {
  [key: string]: string;
  PROJECT_ID: string;

Once the config is instantiated, the datastore class needs to be instantiated, which takes in the config object as it's single constructor paramater.

The datastore should be configured and ready for use.

NestJS Config:


Using the Datastore:

Exposed functions:

createEntity - Creates a new object - Simply pass in a JSON object, and a 'kind' name (see datastore documentation) and that entity will be created. Optionally specify a keyName

readEntity - Read an entity - Read an array of JSON objects from the datastore. Requires a kind, and also a Filter object. (See below for filter object structure). Can optionally also take a {property:string} argument. If included this argument will sort the results and return only the the greatest element in descending order by a simple >= comparison, Will FAIL if property is not sortable numerically (first) or alphabetically

replaceEntity - replace an Entity - *Do a complete 1-1 replacement of an entity with another completely different entity.

editEntity - Edit an entity - *Edit any entity. Requires you to pass in an id, a kind, and an array of new values. The new values array is an array of key-value pairs representing TOP level of keys and values:

eg. Say you pass in: [{age:4}, geolocation:{lat:35,lng:65}] into the third argument of the edit function.

 This is basically saying for a given entity, replace the age property and the geolocation property wit the included values. (Will create those keys if they don't exist)

  ie: {"geolocation":{"lat":3,"lng":3}, "age":3}

 to replace only lat, you will need to replace the whole geolocation object, and pass in a new geolocation object as the third parameter.

 To replace age, you simply need to pass in {"age":5} as the third parameter.

 The edit occurs on the TOP level of the JSON object.

deleteEntity - removes an entity - Simply takes in kind and keyname.

What is a filter?

A filter is a JSON object used by the readEntity function to quickly filter elements.

The type definition is as follows

export type datastoreFilterComparator = '=' | '>' | '>=' | '<' | '<=';

export interface filter {
  property: string;
  comparator: datastoreFilterComparator;
  searchValue: string | number | object | boolean;

By passing in a filter to the readEntity function you can read entities where the property is filtered by some sort of criteria.

The readEntity function takes in an ARRAY of filters, so multiple criteria can be used but BEWARE: The filters are applied sequentially so the ORDER of the filtering does matter.


  1. Fix unit tests to work in standalone mode. (not depend on nestJS infrastrucutre)
  2. Finish docstring-ing the datastore functions

Current Tags

  • 0.0.26                                ...           latest (a year ago)

8 Versions

  • 0.0.26                                ...           a year ago
  • 0.0.25                                ...           a year ago
  • 0.0.24                                ...           a year ago
  • 0.0.23                                ...           a year ago
  • 0.0.22                                ...           a year ago
  • 0.0.21                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 8
Dependencies (4)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2017 © |