Coder Social home page Coder Social logo

level-push's Introduction

level-push

Pushes JSON to your LevelDB with auto-generated UUID. Uses level-set to convert JSON to LevelDB data structure.

Install

npm install level-push
var LevelUp = require('levelup'),
    LevelPush = require('level-push');

var db = LevelUp('./testdb');

LevelPush(db);

Push JSON object

var person = { name: 'Maiah', occupation: 'Ninja' };
db.push('/', person, function (err, uuid) {
  if (!err) {
    console.log('Saved person under root path');
    console.log(uuid); // e.g. 01a538b6-5219-495c-bb8d-bbf4117a6ae2
  }
});

This will put key-value pairs LevelDB data structure at the root path prepended with auto-generated uuid.

01a538b6-5219-495c-bb8d-bbf4117a6ae2/name = Maiah
01a538b6-5219-495c-bb8d-bbf4117a6ae2/occupation = Ninja

You can also save any valid JSON structure.

var person = {
  name: 'Maiah',
  occupation: 'Ninja',
  tools: {
    lang: 'js'
  }
};

db.push('/', person, function (err, uuid) {
  if (!err) {
    console.log('Saved person under root path');
    console.log(uuid); // e.g. 01a538b6-5219-495c-bb8d-bbf4117a6ae2
  }
});

This will put key-value pairs LevelDB data structure at the root path prepended with auto-generated uuid.

01a538b6-5219-495c-bb8d-bbf4117a6ae2/name = Maiah
01a538b6-5219-495c-bb8d-bbf4117a6ae2/occupation = Ninja
01a538b6-5219-495c-bb8d-bbf4117a6ae2/tools/lang = js

You can also specify a path other than the root.

var person = { name: 'Maiah', occupation: 'Ninja' };
db.push('/person', person, function (err, uuid) {
  if (!err) {
    console.log('Saved person object');
    console.log(uuid); // e.g. 01a538b6-5219-495c-bb8d-bbf4117a6ae2
  }
});

This will put key-value pairs LevelDB data structure at the person path with auto-generated uuid inserted right after the specified path.

person/01a538b6-5219-495c-bb8d-bbf4117a6ae2/name = Maiah
person/01a538b6-5219-495c-bb8d-bbf4117a6ae2/occupation = Ninja

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.