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

rigiddb

v0.11.1

Published

Object store with an index and strict schema

Downloads

16

Readme

RigidDB

Build Status Coverage Status Dependency Status devDependency Status

A promise based node module for saving searchable plain JavaScript objects to Redis. API methods are executed as atomic Lua scripts to avoid data/index corruption. Inserted data is type checked against a predefined schema.

Node.js v4.0.0 or later required.

Installation

npm install --save rigiddb

Example

const RigidDB = require('rigiddb');

let store = new RigidDB('mydb', 42);

store.setSchema({
    cars: {
        definition: {
            color: { type: 'string', allowNull: true },
            model: { type: 'string', allowNull: false },
            mileage: 'int', // A shortcut for { type: 'int', allowNull: true }
            convertible: 'boolean',
            purchaseDate: 'date'
        },
        indices: {
            first: {
                uniq: true,
                fields: [
                    { name: 'model', caseInsensitive: true },
                    { name: 'color', caseInsensitive: false }
                ]
            },
            second: {
                uniq: false,
                fields: [ 'color' ] // A shortcut for { name: 'color', caseInsensitive: false }
            }
        }
    }
}).then(function(schemaId) {
    return store.create('cars', {
        color: 'blue',
        mileage: 12345,
        convertible: true,
        purchaseDate: new Date('Sun Nov 01 2015 17:41:24 GMT+0000 (UTC)')
    })
}).then(function(id) {
    // id = 1

    return store.find('cars', {
        color: 'blue',
        mileage: 12345
    });
}).then(function(results) {
    // results = [ 1 ]
});

Connection API

new RigidDB(databaseName, revision, redisOptions)

Create a new database connection.

| Argument | Description | |--------------|---------------------------------------------------------------| | dataBaseName | New or existing database name. All Redis keys will be prefixed with the name. | | revision | Revision number of the schema, integer. | | redisOptions | An object containing arguments forwarded to ioredis node module. Supported properties are: host, port, password, and db. |

Database API

Return values

All database API methods return an JavaScript object.

In success case the object contains method (method name) and val (actual return value) properties.

In case of an error, the object contains method (method name) and err (error code, string) properties.

As an example, delete method can return:

{
    method: 'delete',
    err: 'notFound',
}

TODO: list all error codes.

setSchema(schemaDefinition)

Set a schema for the database. Schema can be set once. Future versions of this library will support schema changes and data migration. Validity of a schema is checked before it is activated and persisted. Any other API call is possible only after the schema is set.

| Argument | Description | |------------------|---------------------------------------------------------------| | schemaDefinition | An object that specifies the collections, including the format of collection data. See the example above for supported data type and index definitions. |

getSchema()

Get the previously set schema definition.

create(collection, attributes)

Add a new object to collection.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | attributes | An object that includes values for all attributes listed in the schema. |

Return value

Id of the newly created object, integer.

update(collection, id, attributes)

Update an existing object in collection.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | id | Id of the object to be updated. | attributes | An object that includes values for attributes to be updated. |

delete(collection, id)

Remove an object from collection.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | id | Id of the object to be removed.

get(collection, id)

Get an object from collection

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | id | Id of the object to be fetched.

exists(collection, id)

Check if an object with an id exists

Get an object from collection

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | id | Id of the object to be searched.

list(collection)

Get ids of all object in a collection.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. |

size(collection)

Get the amount of objects in a collection.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. |

multi(transaction)

Execute several API methods in an atomic transaction. Note that the return value of a method call inside the transaction function can't be used as an argument in the following method calls.

Transaction is terminated if any of the methods return an error value. In a typical case transaction contains one or more exists() calls to make sure that the some object still exists before creating an object that points to those objects.

| Argument | Description | |--------------|---------------------------------------------------------------| | transaction | Transaction function. |

find(collection, searchAttributes)

Find an object using one of the specified indices.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. | | searchAttributes | An object that includes values to be searched. |

debugPrint(collection)

Print the contents of a collection.

Only usable with smalle collections during development.

| Argument | Description | |--------------|---------------------------------------------------------------| | collection | Name of the collection. |

quit()

Terminate the database connection.

Supported data types

  • Boolean ('boolean')
  • Integer and float ('int')
  • String ('string')
  • Date ('date')
  • Unix timestamp ('timestamp')