【发布时间】:2018-09-07 11:44:40
【问题描述】:
是否可以在我的 React Native 应用程序中预加载/预填充数据库,然后在第一次运行时,只需进行同步?在分发应用程序之前,我已经拥有了大部分(如果不是全部)数据库信息,如果它只需要在应用程序运行时进行快速同步,那就太棒了。有什么想法我会如何去做吗?
我找到了这个 - https://pouchdb.com/2016/04/28/prebuilt-databases-with-pouchdb.html,但它没有提到 React Native
使用:
- pouchdb 查找:^7.0.0
- pouchdb-react-native: ^6.4.1
- 反应:16.3.1
- 反应时刻:^0.7.9
- 反应原生:~0.55.2
感谢您的任何指点。
更新这是我用来尝试加载转储文件的代码。此代码存在于 /screens/Home.js 转储文件位于 /client/dbfile/database.txt
var db = new PouchDB("cs1");
db.get("_local/initial_load_complete")
.catch(function(err) {
console.log("loading dumpfile");
if (err.status !== 404) {
// 404 means not found
throw err;
}
db.load("/client/dbfile/database.txt").then(function() {
return db.put({ _id: "_local/initial_load_complete" });
});
})
.then(function() {
// at this point, we are sure that
// initial replication is complete
console.log("loading is complete!");
return db.allDocs({ include_docs: true });
})
.then(
function(res) {
// display all docs for debugging purposes (empty)
console.log(res);
});
this.localDB = db;
当它运行时,我的控制台会显示 - 显示已添加 0 行。
Object {
"offset": 0,
"rows": Array [],
"total_rows": 0,
}
Possible Unhandled Promise Rejection (id: 0):
Object {
"message": undefined,
"name": "unknown",
"status": 0,
}
【问题讨论】:
-
跟进:我尝试从上述文章中的转储文件加载,但收到
db.load is not a function. (In 'db.load("client/dbfile/database.txt")', 'db.load' is undefined)错误消息 -
能分享一下代码吗?
-
跟进:解决了负载未定义的问题,我必须安装这个github.com/pouchdb-community/pouchdb-load 并添加插件
PouchDB.plugin(require('pouchdb-load'));但是,我没有取回任何文档。用一些代码更新我最初的问题
标签: react-native pouchdb