Skip to content

Commit bde0dc0

Browse files
committed
docs: add installation section to README and fix links
1 parent 2c97c76 commit bde0dc0

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@
3535
3636
Nitro SQLite embeds the latest version of SQLite and provides a low-level JSI-backed API to execute SQL queries.
3737

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.
4139

4240
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.
4341

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`.
45+
46+
```bash
47+
npm install react-native-nitro-sqlite react-native-nitro-modules
48+
```
49+
50+
# API
4551

4652
```typescript
4753
import {open} from 'react-native-nitro-sqlite'
@@ -69,7 +75,7 @@ db = {
6975
}
7076
```
7177

72-
### Simple queries
78+
## Simple queries
7379

7480
The basic query is **synchronous**, it will block rendering on large operations, further below you will find async versions.
7581

@@ -96,7 +102,7 @@ try {
96102
}
97103
```
98104

99-
### Transactions
105+
## Transactions
100106

101107
Throwing an error inside the callback will ROLLBACK the transaction.
102108

@@ -125,7 +131,7 @@ await NitroSQLite.transaction('myDatabase', (tx) => {
125131
});
126132
```
127133

128-
### Batch operation
134+
## Batch operation
129135

130136
Batch execution allows the transactional execution of a set of commands
131137

@@ -142,11 +148,11 @@ const res = NitroSQLite.executeSqlBatch('myDatabase', commands);
142148
console.log(`Batch affected ${result.rowsAffected} rows`);
143149
```
144150

145-
### Sending and receiving nullish values
151+
## Sending and receiving nullish values
146152

147153
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:
148154

149-
#### Default null handling
155+
### Default null handling
150156

151157
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**.
152158

@@ -174,7 +180,8 @@ if (isNitroSQLiteNull(firstItem.age) {
174180
}
175181
```
176182
177-
#### Simplified null handling
183+
### Simplified null handling
184+
178185
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()`:
179186
180187
```typescript
@@ -197,7 +204,7 @@ if (firstItem.age === null) { // Nullish values will always be null and never un
197204
198205
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.
199206
200-
### Dynamic Column Metadata
207+
## Dynamic Column Metadata
201208
202209
In some scenarios, dynamic applications may need to get some metadata information about the returned result set.
203210
@@ -218,7 +225,7 @@ metadata.forEach((column) => {
218225
});
219226
```
220227
221-
### Async operations
228+
## Async operations
222229
223230
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.
224231
@@ -232,7 +239,7 @@ NitroSQLite.executeAsync(
232239
);
233240
```
234241

235-
### Attach or Detach other databases
242+
## Attach or Detach other databases
236243

237244
SQLite supports attaching or detaching other database files into your main database connection through an alias.
238245
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) {
259266
}
260267
```
261268

262-
### Loading SQL Dump Files
269+
## Loading SQL Dump Files
263270

264271
If you have a plain SQL file, you can load it directly, with low memory consumption.
265272

@@ -280,17 +287,7 @@ NitroSQLite.loadFileAsync('myDatabase', '/absolute/path/to/file.sql').then(
280287
);
281288
```
282289

283-
## Use built-in SQLite
284-
285-
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
294291

295292
This library is pretty barebones, you can write all your SQL queries manually but for any large application, an ORM is recommended.
296293

@@ -355,12 +352,24 @@ datasource = new DataSource({
355352

356353
# Loading existing DBs
357354

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.).
359356

360357
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.
361358

362359
Alternatively, you can place/move your database file using one of the many react-native fs libraries.
363360

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+
364373
## Enable compile-time options
365374

366375
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
405414

406415
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)
407416

408-
## Community Discord
417+
# Community Discord
409418

410419
[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-nitro-sqlite or other Margelo libraries.
411420

412-
## License
421+
# License
413422

414423
MIT License.

0 commit comments

Comments
 (0)