WebSQL的简单按口:LalaWebSQL

jopen 9年前

简单的WebSQL接口

安装

You can get it on bower.

bower install lala-web-sql --save

创建和更新表格

var db = new LalaWebSQL({    name : 'myDatabase'  });    db.createTable('client', {    id : 'pk',    name : 'string'  }).then(function () {    console.log('Table sucessfully created');  });

更新表格

db.addColumn('client', {    document : 'string'  });    db.createIndex('client', 'document', true); // Parameters: table name, field name, is unique

插入行

db.insert('client', {    name : 'Jonh Doe'  });    db.insertOrReplace('client', {    id : 1,    name : 'Jonh Doe'  });

构建查询

// All results    db.query('client').filter('name', 'Jonh Doe').then(function (rows) {    console.log(rows);  });    // First result    db.query('client').orderBy('name').first().then(function (row) {    console.log(row);  });    // Using raw SQL queries    db.query('client').condition('age > ?', [18]).then(function (rows) {    console.log(rows);  });

删除行

db.query('client').condition('age > ?', [18]).del();

项目主页:http://www.open-open.com/lib/view/home/1446967645844