Create a gstore instance
Instantiate
In order to get a gstore instance, import the module and then call it and provide an optional configuration object. The gstore instances are cached so you can do this in multiple places of your application, the same instance will always be returned.
Configuration
Optionally you can provide a configuration object when creating the instance with the following properties:
namespace (string)
String (default: "gstore-node"
)
This allows you to create multiple instances of gstore. The following example will create 2 instances of gstore that can connect to 2 different Datastore client instances (see below).
errorOnEntityNotFound
Boolean (default: true
)
By default if you fetch an entity by Key and the entity is not found in the Datastore, gstore will throw an "ERR_ENTITY_NOT_FOUND" error. If you prefer to have null
returned when an entity is not found, set errorOnEntityNotFound
to false
.
cache
Refer to the cache documentation for a detail explanation of the cache configuration.
Connect to the Google Cloud Node library
For all the information on how to configure the Goolge Datastore client, read the docs here.
Aliases
After connecting gstore to the datastore, gstore has 2 aliases set up
gstore.ds
The underlying @google/datastore instance. This allows you to access the full API of the Datastore client whenever needed.gstore.transaction
. Alias of the same google-cloud/datastore method
Last updated