Tigger.io 访问设备 sqlite db

Tigger.io accessing device sqlite db

本文关键字:sqlite db io 访问 Tigger      更新时间:2023-09-26

有没有js通过 Trigger.io 访问设备(iOS和Android)sqlite数据库的例子?

可以使用普通的 Web 数据库 API:http://www.w3.org/TR/webdatabase/

注意:并非所有浏览器都支持 Web SQL http://caniuse.com/#feat=sql-storage

例如,我们运行的一个测试类似于以下内容:

var db = openDatabase('mydb', '1.0', 'example database', 2 * 1024 * 1024);
db.transaction(function (tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');  
    tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")');
});
db.transaction(function (tx) {
    tx.executeSql('DROP TABLE foo');
    // known to fail - so should rollback the DROP statement
    tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")');
    forge.logging.error("INSERT into non-existent table succeeded!");
}, function (err) {
    forge.logging.info("error callback invoked, as expected");
});
db.transaction(function (tx) {
    tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
        forge.logging.info("row: "+results);
    });
});

现在你应该使用像LocalForage这样的东西,因为这可以从indexedDB回退到webSQL到localStorage,并为你提供一个一致的api。如果您使用的是Angular/Ionic,那么这就是业务:Angular-LocalForage