GithubHelp home page GithubHelp logo

bongo.js's Introduction

Bongo.js

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

  • Insert, save, remove, find, findOne
  • Comparison query operators ($all, $lt, $lte, $gt, $gte, $in, $nin)
  • Mongo-esque key generator (on _id)
  • Pick, limit, skip
  • Automatic versioning and database upgrades
  • Custom filters
  • 11k

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: "[email protected]"
},function(error,id) {
  if(!error) {
    // success
  }
}
});

save

bongo.db('acme').collection('users').save({
  _id: "[key]", //optional
  name: "Jane Doe",
  email: "[email protected]",
  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: "[email protected]"
}, 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

  • After many(?) database version upgrades, sometimes Chrome needs to be restarted.
  • Redefining the same database multiple times in the same pageload is problematic.

License

MIT. Forking is form of flattery.

See also

bongo.js's People

Contributors

aaronshaf avatar

Watchers

Marcelle von Wendland avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.