Skip to content

Instantly share code, notes, and snippets.

@doughsay
Last active December 12, 2015 03:48
Show Gist options
  • Save doughsay/4709486 to your computer and use it in GitHub Desktop.
Save doughsay/4709486 to your computer and use it in GitHub Desktop.
in-memory js db interface idea
db = require './db'
objects = new db.Collection
objects.addIndex {id: db.UNIQUE}
objects.addIndex {type: db.INDEX}
objects.insert {id: 1, name: 'foo' type: 'thing'}
objects.insert {id: 2, name: 'bar' type: 'thing'}
objects.insert {id: 3, name: 'baz' type: 'animal'}
things = objects.query {type: db.EQ 'thing'} #-> [1,2]
thingsWithNameFoo = objects.query {name: db.EQ 'foo'} #-> [1]
objectsWithIdGreaterThan1 = objects.query {id: db.GT 1} #-> [2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment