You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-30Lines changed: 82 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
# react-native-sqlite-storage
2
+
2
3
SQLite3 Native Plugin for React Native for both Android (Classic and Native), iOS and Windows
3
4
4
5
Foundation of this library is based on Chris Brody's Cordova SQLite plugin.
5
6
6
7
Features:
7
-
1. iOS and Android supported via identical JavaScript API.
8
-
2. Android in pure Java and Native modes
9
-
3. SQL transactions
10
-
4. JavaScript interface via plain callbacks or Promises.
11
-
5. Pre-populated SQLite database import from application bundle and sandbox
12
-
6. Windows supports callback API, identical to iOS and Android
8
+
9
+
1. iOS and Android supported via identical JavaScript API.
10
+
2. Android in pure Java and Native modes
11
+
3. SQL transactions
12
+
4. JavaScript interface via plain callbacks or Promises.
13
+
5. Pre-populated SQLite database import from application bundle and sandbox
14
+
6. Windows supports callback API, identical to iOS and Android
13
15
14
16
There are sample apps provided in test directory that can be used in with the AwesomeProject generated by React Native. All you have to do is to copy one of those files into your AwesomeProject replacing index.ios.js.
15
17
@@ -20,19 +22,25 @@ The library has been tested with React 16.2 (and earlier) and XCode 7,8,9 - it w
20
22
Version 3.2 is the first version compatible with RN 0.40.
21
23
22
24
# Installation
25
+
23
26
```
24
27
npm install --save react-native-sqlite-storage
25
28
```
29
+
26
30
Then follow the instructions for your platform to link react-native-sqlite-storage into your project
27
31
28
32
## Promises
29
-
To enable promises, run
33
+
34
+
To enable promises, run
35
+
30
36
```javascript
31
37
SQLite.enablePromise(true);
32
38
```
33
39
34
40
## iOS
41
+
35
42
#### Standard Method
43
+
36
44
** React Native 0.60 and above **
37
45
Run `cd ios && pod install && cd ..`. Linking is not required in React Native 0.60 and above
38
46
@@ -43,17 +51,22 @@ Run `cd ios && pod install && cd ..`. Linking is not required in React Native 0.
43
51
##### With CocoaPods:
44
52
45
53
Add this to your Podfile which should be located inside the ios project subdirectory
54
+
46
55
```ruby
47
56
pod 'React', :path => '../node_modules/react-native'
48
57
pod 'react-native-sqlite-storage', :path => '../node_modules/react-native-sqlite-storage'
49
58
```
59
+
50
60
Or use the sample Podfile included in the package by copying it over to ios subdirectory and replacing AwesomeProject inside of it with the name of your RN project.
51
61
52
62
Refresh the Pods installation
63
+
53
64
```ruby
54
65
pod install
55
66
```
67
+
56
68
OR
69
+
57
70
```ruby
58
71
pod update
59
72
```
@@ -63,21 +76,23 @@ Done, skip to Step 2.
63
76
##### Without CocoaPods:
64
77
65
78
This command should be executed in the root directory of your RN project
79
+
66
80
```shell
67
81
react-native link
68
82
```
69
83
70
84
rnpm and xcode are dependencies of this project and should get installed with the module but in case there are issue running rnpm link and rnpm/xcode are not already installed you can try to install it globally as follows:
85
+
71
86
```shell
72
87
npm -g install rnpm xcode
73
88
```
89
+
74
90
After linking project should like this:
75
91
76
92

77
93
78
94
#### Step 1a. If rnpm link does not work for you you can try manually linking according to the instructions below:
79
95
80
-
81
96
##### Drag the SQLite Xcode project as a dependency project into your React Native XCode project
@@ -249,12 +264,22 @@ var SQLite = require('react-native-sqlite-storage')
249
264
...
250
265
```
251
266
267
+
#### Step 5. Added liteglue to proguard file
268
+
269
+
You may need to add to your proguard-rules.pro file the lines below:
270
+
271
+
```kotlin
272
+
-keep class io.liteglue.** { *; }
273
+
```
274
+
252
275
## Windows
276
+
253
277
**RNW0.63 with Autolinking and above **
254
278
255
279
No manual steps required
256
280
257
281
**ReactNative0.62**
282
+
258
283
### Step1:Update the solution file
259
284
260
285
Add the `SQLitePlugin` project to your solution.
@@ -267,10 +292,9 @@ Add the `SQLitePlugin` project to your solution.
267
292
268
293
Add a reference to `SQLitePlugin` to your main application project. FromVisualStudio2019:
269
294
270
-
1. Right-click main application project > Add > Reference...
295
+
1.Right-click main application project >Add>Reference...
271
296
2.Check `SQLitePlugin` from SolutionProjects
272
297
273
-
274
298
### Step3:Update the `pch.h` file
275
299
276
300
Add `#include "winrt/SQLitePlugin.h"`.
@@ -281,7 +305,6 @@ Add `PackageProviders().Append(winrt::SQLitePlugin::ReactPackageProvider());` be
281
305
282
306
Refer to this guide for more details: https://microsoft.github.io/react-native-windows/docs/next/native-modules-using
283
307
284
-
285
308
## Setting up your project to import a pre-populated SQLite database from application for iOS
286
309
287
310
#### Step1-Create'www' folder.
@@ -313,6 +336,7 @@ Ensure your project structure after previous steps are executed looks like this
313
336
### Step 6 - Adjust openDatabase call
314
337
315
338
Modify you openDatabase call in your application adding createFromLocation param. If you named your database file in step 2 'testDB' the openDatabase call should look like something like this:
339
+
316
340
```js
317
341
318
342
...
@@ -325,6 +349,7 @@ Modify you openDatabase call in your application adding createFromLocation param
325
349
...
326
350
327
351
```
352
+
328
353
For Android, the www directory is always relative to the assets directory for the app: src/main/assets
329
354
330
355
Enjoy!
@@ -335,29 +360,29 @@ Opening a database is slightly different between iOS and Android. Where as on An
335
360
336
361
WARNING: the default location on iOS has changed in version 3.0.0 - it is now a no-sync location as mandated by Apple so the release is backward incompatible.
337
362
338
-
339
-
To open a database in default no-sync location (affects iOS *only*)::
363
+
To open a database in default no-sync location (affects iOS _only_)::
You can import an existing - prepopulated database file into your application. Depending on your instructions in openDatabase call, the sqlite-storage will look at different places to locate you pre-populated database file.
395
420
396
-
397
421
Use this flavor of openDatabase call, if your folder is called www and data file is named the same as the dbName - testDB in this example
Use this flavor of openDatabase call if your folder is called data rather than www or your filename does not match the name of the db. In this case db is named testDB but the file is mydbfile.sqlite which is located in a data subdirectory of www
Use this flavor of openDatabase call if your folder is not in application bundle but in app sandbox i.e. downloaded from some remote location. In this case the source file is located in data subdirectory of Documents location (iOS) or FilesDir (Android).
## Additional options for pre-populated database file
416
452
417
453
You can provide additional instructions to sqlite-storage to tell it how to handle your pre-populated database file. By default, the source file is copied over to the internal location which works in most cases but sometimes this is not really an option particularly when the source db file is large. In such situations you can tell sqlite-storage you do not want to copy the file but rather use it in read-only fashion via direct access. You accomplish this by providing an additional optional readOnly parameter to openDatabase call
Note that in this case, the source db file will be open in read-only mode and no updates will be allowed. You cannot delete a database that was open with readOnly option. For Android, the read only option works with pre-populated db files located in FilesDir directory because all other assets are never physically located on the file system but rather read directly from the app bundle.
@@ -431,11 +475,18 @@ To archieve this, you need to open both databases and to call the attach()-metho
0 commit comments