Socket
Book a DemoInstallSign in
Socket

gcloud-kvstore

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gcloud-kvstore

Use gcloud's Datastore as a key-value store.

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

gcloud-kvstore

Use Datastore as a Key/Value store.

Install

$ npm install --save gcloud-kvstore

Example

var kvstore = require('gcloud-kvstore');
var datastore = require('@google-cloud/datastore')(/*...*/);

var store = kvstore(datastore);

// Set an item.
store.set('todos', ['eat', 'sleep', 'repeat'], function(err, key) {});

// Get an item.
store.get('todos', function(err, todos) {
  // todos:
  //   ['eat', 'sleep', 'repeat']
});

// Delete an item.
store.delete('todos', function(err) {});

How

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 gcloud-kvstore.

With @google-cloud/datastore:

var key = datastore.key(['KeyValue', 'key']);

datastore.save({
  key: key,
  value: 'value'
}, function() {});

datastore.get(key, function() {});

datastore.delete(key, function() {});

With @google-cloud/datastore + gcloud-kvstore:

var store = require('gcloud-kvstore')(datastore);

store.set('key', 'value', function() {});

store.get('key', function() {});

store.delete('key', function() {});

API

kvstore(datastore)

datastore

A @google-cloud/datastore instance.

kvstore#delete(key, callback)

key

Type: String|Number

callback

Type: Function Executed with the same signature as Datastore#delete.

kvstore#get(key, callback)

key

Type: String|Number

callback

Type: Function Executed with (err, value)

kvstore#set(key, value, callback)

key

Type: String|Number

value

Type: *

callback

Type: Function Executed with the same signature as Datastore#save.

Credit

Concept originally created by Patrick Costello: https://github.com/GoogleCloudPlatform/gcloud-node/issues/256#issuecomment-58962323.

License

MIT © Stephen Sawchuk

Keywords

gcloud

FAQs

Package last updated on 17 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts