Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A key/value store based on sqlite for node.js that actually works.
tree: ffadf5c030

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is a key/value store based on sqlite for node.js that actually works.

It was written by Peteris Krumins (
His blog is at  --  good coders code, great reuse.


It's very simple to use, first import the module:

    var Store = require('supermarket');

Then create a new instance of Store, passing in the database filename and
continuation that gets called when the database has been opened,

    Store('users.db', function (error, db) {
        // ... you can use db here ... check for error, too ...

It provides .set and .get methods that are also continuations,

    Store('users.db', function (err, db) {
        db.set('pkrumins', 'cool dude', function (error) {
            // value 'pkrumins' is now set to 'cool dude'
            db.get('pkrumins', function (error, value) {
                console.log(value); // cool dude

It also has .filter function that takes a predicate, callback and done function.
The .filter function calls callback on each row for which predicate is true.
After it's done filtering, it calls done function.

Here is an example:

    Store('users.db', function (err, db) {
        var users = [];
            function (user, userInfo) { //1//
                return JSON.parse(userInfo).age < 20
            function (err, user, userInfo) { //2//
                if (err) throw err;
            function () { //3//
                console.log("Users younger than 20:");
                users.forEach(function (user) {

In this example it's assumed that users are stored in the database as JSON objects.
The keys are usernames and values are JSON objects.
The filter function here takes the predicate function //1//, parses each record and
returns true if user's age is less than 20.
Now if the age is less than 20, filter calls callback function //2//, which adds each
user who's younger than 20 to users array.
Once filter has gone through all the records it calls done function //3//, which then
prints out all usernames of youngters.

Store also has .forEach method that iterates over all of its values,

    Store('users.db', function (db) {
            function (err, key, val) {
                if (err) throw err;
                console.log("User " + key + " is " + JSON.parse(val).age + " old.");
            function () {
                console.log("Done with all users.");

forEach takes a callback and done function. Very similar to .filter.

It also has .all method that returns all keys and all values,

    Store('users.db', function (db) {
        db.all(function (err, users, userInfos) {
            // all users in users (keys)
            // all user infos in userInfos (values)

Another method is .length that returns the number of elements in the store,

    Store('users.db', function (db) {
        db.length(function (len) {
            console.log("There are " + len + " users in users.db database");
This library doesn't end here, our (my and substack's) is to create an object
store, where you can just dump the whole js objects, and then restore them back,
map, filter and fold on them, etc.


Have fun storing those keys and values!

Peteris Krumins

Something went wrong with that request. Please try again.