HTML5 javascript database library for web app.
Work on all browsers
Support all desktop, mobile and web client browsers utilizing IndexedDB, WebSQL and localStorage. No dependency.
- Chrome 4+ (IndexedDB or WebSql)
- Firefox 3+ (IndexedDB draft), Firefox 10+ (IndexedDB)
- IE 6 (userdata), IE7+ (localStorage), IE10+ desktop/mobile (IndexedDB)
- Safari 3.1+ desktop/mobile/iOS web client (WebSql)
- Android web client, Android browser 2.1+ (WebSql), 4+ (IndexedDB)
- Opera 10+ (WebSql), Opera 15+ (IndexedDB)
Beautiful API
The library API is carefully designed so that it is simple, powerful and make sense.
var db = new ydn.db.Storage('db-name'); db.put('store-name', {message: 'Hello world!'}, 'id1'); db.get('store-name', 'id1').always(function(record) { console.log(record); });
Rich queries
Fast indexed query on client database with multiple filters, ordering and pagination.
var q = db.from('people').where('age', '>=', 25); q.list(10).done(function(peoples) { console.log(peoples); // list of first 10 peoples });
var q = db.from('people').where('country', '=', 'US').order('name'); q.list(10).done(function(peoples) { console.log(peoples); // list of first 10 peoples from US ordered by name }); q.list(10).done(function(peoples) { console.log(peoples); // next 10 peoples });
Unified managed schema
Manage database table or object stores as defined by simple javascript object. Schema could optionally be versioned or let library to generate dynamically.
var schema = { stores: [{ name: 'people', indexes: [{ keyPath: 'age' }, { name: 'age, name', keyPath: ['age', 'name'] }] ] } var db = new ydn.db.Storage('db-name', schema);
Complex transaction workflow
Run complex transaction workflow over hundreds of indexes on millions of records.
db.run(function health_10up(tx_db) { tx_db.get('player', 1).done(function(p1_obj) { p1_obj.health += 10; tx_db.put('player', p1_obj); }); }, ['player'], 'readwrite');
High performance streaming API
Reduce memory usage and fast UI respond by using streaming API.
var q = db.from('author').where('first', 'starts', input_value); var ul = document.getElementById('auto-suggestion-list'); ul.innerHTML = ''; q.open(function (cursor) { var li = document.createElement('li'); var people = cursor.getValue(); li.textContent = people.first + ' ' + people.last; });
Synchronize with REST backend services
Cache and persists in RESTful backend service.
var schema = { stores: [{ name: 'todo', keyPath: 'id', Sync: { format: 'gcs', // Google Cloud Storage Options: { bucket: 'ydn-note-data', prefix: 'todo/' } } }] }; var db = new ydn.db.Storage(db_name, schema); // GET https://ydn-note-data.storage.googleapis.com/todo/id123 db.get('todo', 'id123'); // PUT https://ydn-note-data.storage.googleapis.com/todo/id123 db.put('todo', 'id123'); // DELETE https://ydn-note-data.storage.googleapis.com/todo/id123 db.remove('todo', 'id123');