gpt4 book ai didi

ios - Phonegap + 数据库存储

转载 作者:行者123 更新时间:2023-11-29 02:21:03 25 4
gpt4 key购买 nike

在我的应用程序中,我需要导入 Facebook 联系人。存储联系人信息的最佳做法是什么?

我有两个选择:

  1. 本地存储
  2. 外部数据库(例如mysql)

谢谢!

最佳答案

我会建议 this SQLite wrapper

它的使用非常简单。类似web sql的使用

// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: "my.db"});
// ...
}

例子:

// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: "my.db"});

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');

// demonstrate PRAGMA:
db.executeSql("pragma table_info (test_table);", [], function(res) {
console.log("PRAGMA res: " + JSON.stringify(res));
});

tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");

db.transaction(function(tx) {
tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
});

}, function(e) {
console.log("ERROR: " + e.message);
});
});
}

在插件文档中查看更多内容。

关于ios - Phonegap + 数据库存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28133380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com