在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"},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"},errorCallback);
  // if your folder is not in app bundle but in app sandBox i.e. downloaded from some remote location.
  ...

以上陈述将做什么?
它会创建数据库还是会打开wwwasset文件夹中的数据库
我可以在所需的任何文件夹中创建数据库吗?

没有,我在此找到明确的答案。这就是为什么我在stackoverflow中问这个问题。

解决方法

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