Use Datastore as a Key/Value store.
$ npm install google-cloud-kvstore
const {KVStore} = require('google-cloud-kvstore');
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const store = new KVStore(datastore);
// Set an item.
store.set('todos', ['eat', 'sleep', 'repeat'], (err, key) => {});
// Get an item.
store.get('todos', (err, todos) => {
// todos:
// ['eat', 'sleep', 'repeat']
});
// Delete an item.
store.delete('todos', (err) => {});
Google Cloud Datastore is a managed, NoSQL, schemaless database for storing non-relational data. Datastore entities are complex objects. However, we can wrap this complexity to mimic a simple key/value store by storing a numeric or string "key" as the id of an entity.
The example below shows the complexity that is hidden with google-cloud-kvstore
.
const key = datastore.key(['KeyValue', 'key']);
datastore.save({
key: key,
value: 'value'
}, () => {});
datastore.get(key, () => {});
datastore.delete(key, () => {});
const {KVStore} = require('google-cloud-kvstore');
const store = new KVStore(datastore);
store.set('key', 'value', () => {});
store.get('key', () => {});
store.delete('key', () => {});
A @google-cloud/datastore instance.
Type: String|Number
Type: Function
Executed with the same signature as Datastore#delete.
Type: String|Number
Type: Function
Executed with (err
, value
)
Type: String|Number
Type: *
Type: Function
Executed with the same signature as Datastore#save.
Concept originally created by Patrick Costello: googleapis/google-cloud-node#256 (comment).
MIT