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.
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.
bongo.db({
name: 'acme',
collections: ["users"]
});
bongo.db('acme').collection('users').insert({
name: "John Doe",
email: "john@domain.com"
},function(error,id) {
if(!error) {
// success
}
}
});
bongo.db('acme').collection('users').save({
_id: "[key]", //optional
name: "Jane Doe",
email: "jane@domain.com",
pets: 3
});
bongo.db('acme').collection('users').get("[key]", function(error,data) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
name: "John Doe"
}).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
name: /john/i
}).toArray(function(error,results) {
if(!error) {
//success
}
});
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.
bongo.db('acme').collection('users').findOne({
name: "John Doe"
}),function(error,record) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').filter(function(doc) {
return doc.age > 30;
}).toArray(function(error,results) {
if(!error) {
//success
}
});
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
}
});
bongo.db('acme').collection('users').find({
age: {$gt: 30}
}).limit(5).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
age: {$gt: 30}
}).skip(5).limit(5).toArray(function(error,results) {
if(!error) {
//success
}
});
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
}
});
bongo.delete(function(error) {
if(!error) {
// Success
}
});
if(bongo.supported) {
// Woo hoo!
}
MIT. Forking is form of flattery.