我正在创建一个应用程序,它可以用react-native-sqlite-storage保存本地手机内存中的数据。
我希望创建一个脚本来创建一个数据库(如果不存在的话),创建必要的表,然后用模拟数据填充这些表(基本上是种子脚本)。我计划在我的package.json中添加一个脚本来为这些数据添加种子,如下所示
{
....
"scripts": {
....
"seed": "ts-node index.ts"
}
}其中index.ts将包含必要的种子脚本,如下所示:
// import react-native-sqlite-storage
const seedDatabase = () => {
// Populate the data ...
}
seedDatabase();但我不确定这是否可行。它能用吗?如果没有,是否有一种种子数据的方法?
发布于 2022-11-08 16:53:18
您可以使用此包创建和填充数据库https://www.npmjs.com/package/sqlite3
adb push your_db.db /storage/emulated/0/your_db.db在您的react本机代码中,只需使用https://github.com/andpor/react-native-sqlite-storage#importing-a-pre-populated-database文件
https://stackoverflow.com/questions/72154057
复制相似问题