14th July 2015

sodb is the latest of my little projects to hit npm and I really enjoyed making this one.

It is written in coffee-script and fully tested.

The idea is to have the features of a database table available to an array of objects. You have to admit that {name: 'bob', age: 10, height: 120} already looks a lot like a database record so that is all sodb needs to add a record!

Creating a database is as easy as creating a new object:

1sodb = require 'sodb'
3db = new sodb()
Language coffee

Which can now have objects added to it

1db.add {name: 'bob', age: 10, height: 120}
Language coffee

The database now has 1 entry in it which can be searched for (not that you need to) and updated or removed when ever you want.

Finding records is done through the where method which takes varying arguments like so:

1db.where {name: 'bob'}
2db.where {name {is: 'bob'}} # this is the same as the line above, sodb assumes you mean is
3db.where {age: {gt: 8}}
4db.where {age: {lt: 12}}
5db.where {name: {isnot: 'steve'}}
Language coffee

You can have multiple searches which are run one after another on an ever decreasing set of the results.

1db.where {name: 'bob'}, {age: {gt: 8}}
Language coffee

If you need to find records where X is a or b you can use:

1db.where {name: ['bob', 'kevin']}
Language coffee

sodb also features a cache to help speed up the finding of data in large databases, or to be more specific finding the same data again in a large database.

Caching uses a hash of of the search object(s) to store the returned results and then returns them to you if they exist.

sodb was written for an as yet unreleased version of express-permissions which needed the permissions to be stored where I could run a query like:

1db.where {route: '/foo/bar'}, {method: ['get', 'all']}
Language coffee