Git Product home page Git Product logo

nodejs-datastore-kvstore's Introduction

google-cloud-kvstore

Use Datastore as a Key/Value store.

Install

$ npm install google-cloud-kvstore

Example

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) => {});

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 google-cloud-kvstore.

With @google-cloud/datastore:

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

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

datastore.get(key, () => {});

datastore.delete(key, () => {});

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

const {KVStore} = require('google-cloud-kvstore');
const store = new KVStore(datastore);
store.set('key', 'value', () => {});
store.get('key', () => {});
store.delete('key', () => {});

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: googleapis/google-cloud-node#256 (comment).

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.