WebSQL的簡單按口:LalaWebSQL

jopen 9年前發布 | 7K 次閱讀 JavaScript開發 LalaWebSQL

簡單的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.baiduhome.net/lib/view/home/1446967645844

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!