Skip to content
/ jdb.js Public

jdb.js is a framework that helps coding with Indexed Database API (IDB). As you know, 'J' is the next character of 'I' in alphabetical order, so 'JDB' means the 'Better IDB API':-)

Notifications You must be signed in to change notification settings

shumpei/jdb.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jdb.js - Framework for Indexed Database API

"jdb.js" is a framework for programing easier with W3C Indexed Database API. 'J' is the next character of 'I' in alphabetical order, so "JDB" means "better IDB". Compared with using "naked" Indexed Database API, using jdb.js is better as follows:

  • Object oriented, easy-for-use API.
  • You can define the scheme of the object stores using declarative JSON format.
  • Easy database upgrade at runtime (what you should do on upgrade is only specify "since:version" configuration in definition of object stores or indexes).
  • You can describe the code of asynchronous programming in the intuitive way.

Following code is an example of using jdb.js.

// Create a new reference of the database.
var db = new JDBDatabase('database name', 1);

// Create a new reference of the object store.
var CatStore = new JDBObjectStore({
  name: 'CatStore', // Name of this store.
  database: db,     // Reference of the database.
  key: { path: 'id', autoIncrement: true }, // Definition of the key property.
  indexes: {
    ageIdx: { path: 'age' } // Definition of the index.
  }
});

// Open database connection.
db.open().success(function() {
  console.log('database opened');
});

// Put an object to the object store.
CatStore.put({
  name: 'Nana',
  age: 7,
  gender: 'female'
});

// Get object from the store.
var catId = 1;
CatStore.get(catId, function(cat, error) {
  ...
});

// Iterate all cats in the store.
CatStore.all().iterate(function(cat) {
  ...
});

// Get the cats which age is less equal 5.
var criteria = JDBCriteria.byIndex('ageIdx').le(5);
CatStore.criteria(criteria).list(function(cats) {
  ...
});

For more information, see the tutorial.

CONTRIBUTING IS ALWAYS WELCOME!

About

jdb.js is a framework that helps coding with Indexed Database API (IDB). As you know, 'J' is the next character of 'I' in alphabetical order, so 'JDB' means the 'Better IDB API':-)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published