React-Native-Sqlite-Storage使用應用程序庫文件夾中的子目錄。該目錄被稱爲localDatabase
。複製或下載數據庫或將數據庫移動到該位置(localDatabase
),並使用React-Native-Sqlite-Storage的openDatabase()
函數打開數據庫,同時爲其提供數據庫名稱。
var RNFS = require('react-native-fs');
var SQLite = require('react-native-sqlite-storage');
/*copy file from app bundle to library/localDatabase*/
var sourcePath = RNFS.MainBundlePath + '/' + 'myDatabase.sqlite';
var destinPath = RNFS.RNFS.LibraryDirectoryPath + '/LocalDatabase/' + 'myDatabase.sqlite';
RNFS.copyFile(sourcePath, destinPath)
.then(() =>{
var db = SQLite.openDatabase("myDatabase.sqlite", "1.0", "", 200000, me._openCB, me._errorCB);
})