1

有没有js通过Trigger.io访问设备(ios和android)sqlite db的例子?

4

2 回答 2

2

普通的 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);
    });
});
于 2012-05-09T08:38:03.753 回答
0

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

于 2014-08-11T11:19:28.150 回答