Another high-level API for creating secondary leveldb indexes
Last updated a year ago by bret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install level-idx 
SYNC missed versions from official npm registry.


High Level leveldb indexing API using level-auto-index.

npm install level-idx

level badge npm Build Status dependencies Status devDependencies Status


Index posts by title and body length, then query for them:

var Index = require('level-idx')
var level = require('memdb')
var sub = require('subleveldown')

var db = level()
var posts = sub(db, 'posts', {valueEncoding: 'json'})
var idx = sub(db, 'idx')

Index(posts, idx)
  .by('Title', 'title')
  .by('Length', ['body.length', 'title'])
  .by('Author', ['author', 'title'])

var post = {
  title: 'a title',
  body: 'lorem ipsum',
  author: 'julian'

posts.put('1337', post, function (err) {
  if (err) throw err

  posts.byTitle.get('a title', console.log)
  posts.byLength.get('11!a title', console.log)
  posts.byAuthor.get('julian!a title', console.log)


Index(db, idb)

Index db into idb.

Index#by(name, props)

Create an index called name and index by props.

props should be a string or an array of strings that each name a property. Deep object access is enabled via deep-access. Use multiple properties if you can't guarantee the uniqueness of the first property's value.

If a property doesn't exist, e.g. if you want to index by body.length but there is no key body, it will be ignored.


The underlying db.

Index.db.by{Name}.get(key[, opts], fn)


See level-auto-index.


Populate db.methods with the manifests of each indexed db.object:

var index = require('level-idx');
var createManifest = require('level-manifest');

db.methods = {};
db.posts = index(db.sublevel('posts'))
  .by('Slug', ['slug'])
db.methods.posts = {
  type: 'object',
  methods: createManifest(db.posts).methods

See Also

This module is a port of juliangruber/level-sec that works/uses subleveldown and level-auto-index.

Current Tags

  • 2.0.0                                ...           latest (a year ago)

2 Versions

  • 2.0.0                                ...           a year ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (3)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |