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

icecave

v2.0.0

Published

Fast and simple flat file storage for small projects

Downloads

13

Readme

IceCave DB

Build Status npm version Dependency Status

A lightweight flat file storage system for nodejs.

Query using JSON schema and update using JSON patch.

IceCave is designed for use in applications where relatively small amounts of data (less than 10000 elements) need to be stored persistently and a dedicated external database service is impractical or overkill. IceCave stores data in-memory and periodically dumps it's contents to a JSON file. On startup it will read this file location and load any data found there.

Usage

Below is an example how to use IceCave DB:

const IceCave = require('icecave');

// Create a new storage instance that will be written to the directory './data-directory'
const db = new IceCave({
  directory: __dirname + '/data-directory',
})

// Add elements to the database
db.insert({ id: 1, name: 'Abra' })
db.insert({ id: 2, name: 'Bulbasaur' })
db.insert({ id: 3, name: 'Caterpie' })

// Find an element
const user = db.query({
  type: 'object',
  properties: {
    id: {
      type: 'string',
      const: 2
    }
  }
}) // --> { id: 2, name: 'Bulbasaur' }

// Update an element
const user = db.update({
  type: 'object',
  properties: {
    id: {
      type: 'string',
      const: 2
    }
  }
}, [
  { op: 'replace', path: '/name', value: 'Beedrill' },
  { op: 'add', path: '/type', value: [ 'bug', 'poison' ] }
]) // --> { id: 2, name: 'Beedrill', type: [ 'bug', 'poison' ] }

// Delete an element
const user = db.delete({
  type: 'object',
  properties: {
    id: {
      type: 'string',
      const: 3
    }
  }
})

Documentation

IceCave instance

Kind: global class
Summary: Create an instance of IceCave
Access: public

new IceCave(config)

| Param | Type | Default | Description | | --- | --- | --- | --- | | config | Object | | Configuration object | | [config.directory] | String | ./icecave-data | The directory where icecave data is stored | | [config.name] | String | icecave | The name of this instance | | [config.memoryOnly] | Boolean | false | Set to true to stop the db from being written to the filesystem |

Example

const db = new IceCave()

iceCave.dump() ⇒ Promise.<String>

Dumps the store to a JSON file and shuts down the DB

Kind: instance method of IceCave
Summary: Writes the in memory storage to a JSON file.
Returns: Promise.<String> - The path of the stored JSON file
Access: public
Example

const db = new IceCave()

await db.dump()

iceCave.insert(element)

Insert an element into the database

Kind: instance method of IceCave
Access: public

| Param | Type | Description | | --- | --- | --- | | element | Object | The element to insert |

Example

const db = new IceCave()

db.insert({
  foo: 'bar',
  baz: 'buzz'
})

iceCave.delete(query)

Delete elements in the store the match a JSON schema.

Kind: instance method of IceCave
Access: public

| Param | Type | Description | | --- | --- | --- | | query | Object | The JSON schema to validate against |

Example

const db = new IceCave()

db.insert({
  foo: 'bar',
  baz: 'buzz'
})

db.delete({
  type: 'object',
  properties: {
    foo: {
      const: 'bar'
    }
  }
})

iceCave.filter(query) ⇒ Array

Retrieve elements in the store that match a JSON schema.

Kind: instance method of IceCave
Returns: Array - An array of elements
Access: public

| Param | Type | Description | | --- | --- | --- | | query | Object | The JSON schema to validate against |

Example

const db = new IceCave()

db.insert({
  foo: 'bar',
  baz: 'buzz'
})

const results = db.filter({
  type: 'object',
  properties: {
    foo: {
      const: 'bar'
    }
  }
})

console.log(results)

iceCave.update(query, patch)

Select elements that match a JSON schema and update them using a JSON patch object.

Kind: instance method of IceCave
Summary: Update one or more elements
Access: public
See: https://tools.ietf.org/html/rfc6902

| Param | Type | Description | | --- | --- | --- | | query | Object | The JSON schema to validate against | | patch | Object | An RFC 6902 JSON patch object |

Example

const db = new IceCave()

db.insert({
  foo: 'bar',
  baz: 'buzz'
})

db.update({
  type: 'object',
  properties: {
    foo: {
      const: 'bar'
    }
  }
},
[
  { "op": "replace", "path": "/baz", "value": "boo" }
])

iceCave.shutdown() ⇒ Promise

Dumps the store to a JSON file and shuts down the DB

Kind: instance method of IceCave
Summary: Shutdown the database
Access: public
Example

const db = new IceCave()

await db.shutdown()