npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

levelgo

v1.6.0

Published

Simple document store with indexing

Downloads

25

Readme

levelgo

Indexed collections for LevelDB (inspired by MongoDB)

Build Status

Install

npm i levelgo

Example

import levelgo from 'levelgo'

const db = levelgo('example-db')

db.collection('books')  
db.books.registerIndex({ author: 1 })

await db.books.put('book1', { 
  author: 'Hemingway', 
  title: 'Islands in the Stream',
  year: 1970
})

const book = await db.books.get('book1')
const books = await db.books.find({ author: 'Hemingway' })

API

db = levelgo( location )

  • location {String} path of the LevelDB location to be opened, or in browsers, the name of the IDBDatabase to be opened

db.collection( name )

  • name {String} name of the collection to initialize

Collection methods

db.name.del( id )

  • id {String|Number} primary key of the value to delete

db.name.find( [query] )

  • query {Object} optional selection filter. An index with the same fields must be registered. If blank or empty object, returns all values in the collection.

  • Mongo-style comparison query operators are available:

    • $gt
    • $lt
    • $gte
    • $lte
    • $in
    • $nin
    • $eq
    • $ne
  • Note: null, undefined and "empty string" values are indexed the same as "blank" values.

db.name.findKeys( [query] )

  • query {Object} optional selection filter. An index with the same fields must be registered. If blank or empty object, returns all keys (ids) in the collection.

db.name.get( id )

  • id {String|Number} primary key of the value to retrieve

db.name.put( id, value )

  • id {String|Number} primary key of the value to store
  • value {mixed} any stringify-able value to store in the collection

db.name.registerIndex( fields )

  • fields {Object} fields to be indexed. Always set the value of each field to 1 since only ascending indices are currently supported.

Atomic Batch

batch = db.batch()

batch.name.del( id )

batch.name.put( id, value )

batch.write()

Advanced Example

import levelgo from 'levelgo'

const db = levelgo('example-db')

db.collection('books')

// you can have compound nested indices
db.books.registerIndex({ 
  tags: 1,
  'reviews.stars': 1
})

// batch operations are written atomically
const batch = db.batch()
batch.books.del('book1')
batch.books.put('book2', { 
  author: 'Hemingway', 
  title: 'Islands in the Stream',
  year: 1970,
  reviews: [
    { stars: 5, username: 'taylor' },
    { stars: 4, username: 'river' },
  ],
  tags: ['classic']
})
await batch.write()

// find books that are tagged 'classic' that have at least one review of 4+ stars
const books = await db.books.find({ 
  'reviews.stars': { $gte: 4 },
  tags: 'classic'
})