Create a gstore instance
Instantiate
In order to get a gstore instance, import the module and create a new instance with an optional configuration object.
Configuration
Optionally you can provide a configuration object when creating the instance with the following properties:
cache
Refer to the cache documentation for a detail explanation of the cache configuration.
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
.
Connect the Google Cloud Node library
For all the information on how to configure and instantiate the Datastore client, read the docs here.
Aliases
After connecting gstore to the datastore, the gstore instance has 2 aliases set up
gstore.ds
The underlying @google/datastore instance. This allows you to access the complete API of the Datastore client whenever needed.gstore.transaction
. Alias of the same google-cloud/datastore method.
Instances
Each time you call const gstore = new Gstore()
you create a new instance. This means that you are responsible to cache that instance to be able to retrieve it in different places of your application. One way to do that is to initialise gstore in a separate file and require the instance from there.
Another way is to use gstore instances
to save and retrieve gstore instances.
Last updated