如何在react native中使用sqlite3创建数据库



我浏览了这个链接中的所有细节https://github.com/andpor/react-native-sqlite-storage.我对他们的文件感到困惑。

...
1.SQLite.openDatabase({name : "testDB", createFromLocation : 1}, okCallback,errorCallback);
// default - if your folder is called www and data file is named the same as the dbName - testDB in this example
2.SQLite.openDatabase({name : "testDB", createFromLocation : "~data/mydbfile.sqlite"}, okCallback,errorCallback);
// if your folder is called data rather than www or your filename does not match the name of the db
3.SQLite.openDatabase({name : "testDB", createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);
// if your folder is not in app bundle but in app sandbox i.e. downloaded from some remote location.
...

以上陈述将起到什么作用
它会创建一个数据库,还是会打开wwwasset文件夹中的数据库
我可以在我想要的任何文件夹中创建数据库吗?

没有,我在哪里找到了明确的答案。这就是为什么我要在斯塔克弗洛问这个问题。

我以前也遇到过同样的问题。您需要根据文档进行所有设置。之后,如果您使用createFromLocation提供database.db的位置,则必须创建一个空的数据库文件并手动将其粘贴到资源中,如果您不想手动创建,则可以简单地使用SQLite.openDatabase({name : "testDB"}),它将根据提供的名称为自己创建一个数据库。希望这对你有帮助,请告诉我它是否有效。

最新更新