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
+37-28Lines changed: 37 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,13 +35,19 @@
35
35
36
36
Nitro SQLite embeds the latest version of SQLite and provides a low-level JSI-backed API to execute SQL queries.
37
37
38
-
Performance metrics are intentionally not presented, [anecdotic testimonies](https://dev.to/craftzdog/a-performant-way-to-use-pouchdb7-on-react-native-in-2022-24ej) suggest anywhere between 2x and 5x speed improvement. On small queries you might not notice a difference with the old bridge but as you send large data to JS the speed increase is considerable.
39
-
40
-
Starting on version `8.0.0` only React-Native `0.71` onwards is supported. This is due to internal changes to React-Native artifacts. If you are on < `0.71` use the latest `7.x.x` version.
38
+
Starting from version `9.0.0` only React-Native `0.71` onwards is supported. This is due to internal changes to React-Native artifacts. If you are on < `0.71` use the latest `7.x.x` version.
41
39
42
40
TypeORM is officially supported, however, there is currently a parsing issue with React-Native 0.71 and its babel configuration and therefore it will not work, nothing wrong with this package, this is purely an issue on TypeORM.
43
41
44
-
## API
42
+
# Installation
43
+
44
+
NitroSQLite depends on [Nitro modules](https://nitro.margelo.com/). The minimum version of Nitro can be found in the `peerDependencies` in `package.json`.
Due to internal limitations with Nitro modules, we have to handle nullish values explicitly in NitroSQLite. There are two ways to send and receive null values:
148
154
149
-
####Default null handling
155
+
### Default null handling
150
156
151
157
By default, the user can pass the `NITRO_SQLITE_NULL` constant instead of `null` or `undefined` to query params and will also receive this constant for nullish values in e.g. `SELECT` queries. `NITRO_SQLITE_NULL` is the object that is used internally to handle nullish values, therefore **this approach does NOT introduce any performance overhead**.
152
158
@@ -174,7 +180,8 @@ if (isNitroSQLiteNull(firstItem.age) {
174
180
}
175
181
```
176
182
177
-
#### Simplified null handling
183
+
### Simplified null handling
184
+
178
185
To enable simple null handling, call `enableSimpleNullHandling()` in the root of your project. This will allow you to just pass `null` or `undefined` to NitroSQLite functions, e.g. as query params. in `execute()`:
179
186
180
187
```typescript
@@ -197,7 +204,7 @@ if (firstItem.age === null) { // Nullish values will always be null and never un
197
204
198
205
Simple null handling adds some logic to internally transform nullish values into a special object/struct and vice versa, that is sent/received from the native C++ side. This **might introduce some performance overhead**, since we have to loop over the params and query results and check for this structure.
199
206
200
-
### Dynamic Column Metadata
207
+
## Dynamic Column Metadata
201
208
202
209
In some scenarios, dynamic applications may need to get some metadata information about the returned result set.
You might have too much SQL to process and it will cause your application to freeze. There are async versions for some of the operations. This will offload the SQLite processing to a different thread.
224
231
@@ -232,7 +239,7 @@ NitroSQLite.executeAsync(
232
239
);
233
240
```
234
241
235
-
###Attach or Detach other databases
242
+
## Attach or Detach other databases
236
243
237
244
SQLite supports attaching or detaching other database files into your main database connection through an alias.
238
245
You can do any operation you like on this attached database like JOIN results across tables in different schemas, or update data or objects.
@@ -259,7 +266,7 @@ if (!detachResult.status) {
259
266
}
260
267
```
261
268
262
-
###Loading SQL Dump Files
269
+
## Loading SQL Dump Files
263
270
264
271
If you have a plain SQL file, you can load it directly, with low memory consumption.
On iOS you can use the embedded SQLite, when running `pod-install` add an environment flag:
286
-
287
-
```
288
-
Nitro_SQLITE_USE_PHONE_VERSION=1 npx pod-install
289
-
```
290
-
291
-
On Android, it is not possible to link (using C++) the embedded SQLite. It is also a bad idea due to vendor changes, old android bugs, etc. Unfortunately, this means this library will add some megabytes to your app size.
292
-
293
-
## TypeORM
290
+
# TypeORM
294
291
295
292
This library is pretty barebones, you can write all your SQL queries manually but for any large application, an ORM is recommended.
296
293
@@ -355,12 +352,24 @@ datasource = new DataSource({
355
352
356
353
# Loading existing DBs
357
354
358
-
The library creates/opens databases by appending the passed name plus, the [documents directory on iOS](https://github.com/margelo/react-native-nitro-sqlite/blob/733e876d98896f5efc80f989ae38120f16533a66/ios/NitroSQLite.mm#L34-L35) and the [files directory on Android](https://github.com/margelo/react-native-nitro-sqlite/blob/main/android/src/main/java/com/margelo/rnnitrosqlite/NitroSQLiteBridge.java#L16), this differs from other SQL libraries (some place it in a `www` folder, some in androids `databases` folder, etc.).
355
+
The library creates/opens databases by appending the passed name plus, the [documents directory on iOS](https://github.com/margelo/react-native-nitro-sqlite/blob/2c97c767cb189cb170941bd1ffb4c8555c0bb9cd/package/ios/OnLoad.mm#L34-L35) and the [files directory on Android](https://github.com/margelo/react-native-nitro-sqlite/blob/2c97c767cb189cb170941bd1ffb4c8555c0bb9cd/package/android/src/main/kotlin/com/margelo/rnnitrosqlite/DocPathSetter.kt#L8), this differs from other SQL libraries (some place it in a `www` folder, some in androids `databases` folder, etc.).
359
356
360
357
If you have an existing database file you want to load you can navigate from these directories using dot notation. e.g. `../www/myDb.sqlite`. Note that on iOS the file system is sand-boxed, so you cannot access files/directories outside your app bundle directories.
361
358
362
359
Alternatively, you can place/move your database file using one of the many react-native fs libraries.
363
360
361
+
# Configuration
362
+
363
+
## Use built-in SQLite
364
+
365
+
On iOS you can use the embedded SQLite, when running `pod-install` add an environment flag:
366
+
367
+
```
368
+
Nitro_SQLITE_USE_PHONE_VERSION=1 npx pod-install
369
+
```
370
+
371
+
On Android, it is not possible to link (using C++) the embedded SQLite. It is also a bad idea due to vendor changes, old android bugs, etc. Unfortunately, this means this library will add some megabytes to your app size.
372
+
364
373
## Enable compile-time options
365
374
366
375
By specifying pre-processor flags, you can enable optional features like FTS5, Geopoly, etc.
@@ -405,10 +414,10 @@ On iOS, the SQLite database can be placed in an app group, in order to make it a
405
414
406
415
To use an app group, add the app group ID as the value for the `RNNitroSQLite_AppGroup` key in your project's `Info.plist` file. You'll also need to configure the app group in your project settings. (Xcode -> Project Settings -> Signing & Capabilities -> Add Capability -> App Groups)
407
416
408
-
##Community Discord
417
+
# Community Discord
409
418
410
419
[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-nitro-sqlite or other Margelo libraries.
0 commit comments