Giter Club home page Giter Club logo

levelup-autotable's Introduction

level-autotable

Auto increment key table for node-levelup, leveldb.

Auto incrementing keys.
Read, write, delete fields in a record individually.
Read, write, delete records.

var db = require('levelup')('./mydb')
require("level-autotable")(db)

You must call initAutoKeys before using the database.

db.initAutoKeys(callback)

You can call this from inside a request handler. Initialization is done the first time round. On subsequent calls it will just call next.

app.use(function(req, res, next) {
    db.initAutoKeys(function() {next()})
})

Get a new key. The key is a string with integer value starting from 1. Use parseInt to do math on the key. Will throw an error if callback is not a function.

var key
db.newAutoKey(function(err, newKey) {
    key = newKey
})

Handle fields individually.
Put a field

db.putField(key, "name", "John", options, callback)
db.putField(key, "email", "[email protected]", options, callback)

The fieldname must be a valid javascript var name. ie only word chars _ and $ allowed. Will throw an error otherwise!

Get a field.

db.getField(key, fieldname, options, callback)

Delete a field.

db.delField(key, fieldname, options, callback)

Get a record.

db.getRecord(key, function(err, value) {
    console.log(value) // {name: "John", email: "[email protected]"}
})

Put a record.

db.putRecord(key, {name: "John", email: "[email protected]"}, function(err) {
    //
})

Delete a record.

db.delRecord(key, function(err) {
    //
})

levelup-autotable's People

Contributors

santoshrajan avatar

Watchers

 avatar

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.