aaronshaf / bongo.js

[Deprecated] Store and query massive amounts of structured data on the browser.
48 stars 4 forks source link

Bongo.js (deprecated)

Bongo.js is a JavaScript library for storing and querying structured data on the browser. Lots of it.

It is built on IndexedDB.

It is tested in Chrome 27, Chrome 29, Firefox 22, and Internet Explorer 10.

Features

Get started

Install

Use Bower:

bower install bongo.js

And include the file in your app:

<script src='/components/bongo.js/dist/bongo.min.js'></script>

You can also download the compressed, production version or the uncompressed, development version.

Define database

bongo.db({
  name: 'acme',
  collections: ["users"]
});

insert

bongo.db('acme').collection('users').insert({
  name: "John Doe",
  email: "john@domain.com"
},function(error,id) {
  if(!error) {
    // success
  }
}
});

save

bongo.db('acme').collection('users').save({
  _id: "[key]", //optional
  name: "Jane Doe",
  email: "jane@domain.com",
  pets: 3
});

get

bongo.db('acme').collection('users').get("[key]", function(error,data) {
  if(!error) {
    //success
  }
});

find

bongo.db('acme').collection('users').find({
  name: "John Doe"
}).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

Regular expressions

bongo.db('acme').collection('users').find({
  name: /john/i
}).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

Comparison query operators

bongo.db('acme').collection('users').find({
  pets: {$gt: 2}
}).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

$all, $lt, $lte, $gt, $gte, $in, $nin are supported.

findOne

bongo.db('acme').collection('users').findOne({
  name: "John Doe"
}),function(error,record) {
  if(!error) {
    //success
  }
});

filter

bongo.db('acme').collection('users').filter(function(doc) {
  return doc.age > 30;
}).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

fields

bongo.db('acme').collection('users').find({
  age: {$gt: 30}
},{
  name: 1,
  email: 1
}).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

or

bongo.db('acme').collection('users').find({
  age: {$gt: 30}
}).pick(['name','email']).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

limit

bongo.db('acme').collection('users').find({
  age: {$gt: 30}
}).limit(5).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

skip

bongo.db('acme').collection('users').find({
  age: {$gt: 30}
}).skip(5).limit(5).toArray(function(error,results) {
  if(!error) {
    //success
  }
});

remove

bongo.db('acme').collection('users').remove({
  email: "john@domain.com"
}, function(error, data) {
  if(!error) {
    //success
  }
})

Or just use the key:

bongo.db('acme').collection('users').remove("[key]", function(error, data) {
  if(!error) {
    //success
  }
});

Delete the database

bongo.delete(function(error) {
  if(!error) {
    // Success
  }
});

Check for support

if(bongo.supported) {
  // Woo hoo!
}

Known issue

License

MIT. Forking is form of flattery.

See also