Using YDN-DB

Recommended usage pattern for YDN-DB module.

Full text search module for YDN-DB database library. This library build on top of two excellent full text search libraries, natural for stemming, normalization, analyzer and fullproof for tokenization.

Handling database connection error

Currently client-side database are temporary storage. The data can be wipe out anytime without informing to user or script. Data corruption instance has been observed to SQLite and Chrome IndexedDB during opening the database. If corruption occur, whole database or only certain object store can wipe out.

The most unpredictable operation is database connection. For an application to robust, storage events dispatched from the storage instance should be listened and validate data integrity.

var db_name = 'test-db-3';
var options = {};
db = new ydn.db.Storage(db_name, author_article_topic_schema, options);
db.addEventListener('ready', function(ev) {
  if (isNaN(ev.getOldVersion())) {
    // new database is created
    var authors = genAuthors(100);
    db.put('author', authors);
  } else if (ev.getVersion() > ev.getOldVersion()) {
    // schema upgrade, do data upgrade as necessary
  } else {
    // existing database open
  }
});
db.addEventListener('fail', function(ev) {
  var err = ev.getError();
  // database connection fail, inform user
  alert('Your data will not be saved, database opening failed wth ' + err.name);
});

Authors

Kyaw Tun