YDN-DB

HTML5 javascript database library for web apps.

Javascript database library for IndexedDB, WebSQL and WebStorage.

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 a simple Javascript object. Schema can be versioned or generated 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 increase UI responsiveness by using the 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 persist in the 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');