sqlite - 我如何知道在 expo 应用程序中完成的 sqlite 数据库加载
问题描述
在应用程序加载后不久执行查询时 SQLite 数据库损坏
这是 Expo(react-native) 应用程序,数据库是从本地存储加载的。
如果我等待几秒钟使用应用程序(执行查询),则问题不会发生。
也许,在从本地存储加载所有数据之前执行查询时会发生此问题。
在 APP.js 中
async function loadResourcesAsync() {
await Promise.all([
FileSystem.makeDirectoryAsync(`${FileSystem.documentDirectory}SQLite`, {
intermediates: true
}).then(
FileSystem.downloadAsync(
Asset.fromModule(require("./assets/db/mydb.db")).uri,
`${FileSystem.documentDirectory}SQLite/mydb.db`
)
)
]);
}
在这样的 Screen.js 中
const db = SQLite.openDatabase("mydb.db");
db.transaction(
tx => {
tx.executeSql(sql, [queryChar], (_, { rows: { _array } }) => {
// console.log(JSON.stringify(_array));
setSearchResult(_array);
});
},
e => {
console.log(e);
});
},
null
);
我期待openDatabase
函数的回调,但它没有这样的回调。
我怎么知道数据库加载完成了?
解决方案
推荐阅读
- reactjs - Office UI Fabric React - 关注表单输入时显示工具提示?
- regex - Pandas 和 reg ex,将文本和数字分解为带有标题的几列
- python - 如何使用python3拆分字符串
- c# - 使用碎片清除后台堆栈
- python - 有条件地重塑熊猫
- c# - 引用 Newtonsoft.Json.dll 时在 mono 下运行时编译 C# 代码失败
- spring - 如何用自定义错误 html 页面替换 Spring Boot 1.3.x 404 错误页面
- c - 在以下场景中,我是服务器还是客户端?
- java - 哈希集没有它应该有的值。实例化问题
- android - 谷歌地图崩溃:java.lang.NullPointerException:尝试从空数组读取