Skip to content

Commit 973d8a4

Browse files
author
Oscar Franco
committed
Update readme
1 parent 1ab3702 commit 973d8a4

2 files changed

Lines changed: 32 additions & 20 deletions

File tree

README.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1 align="center">React Native Quick SQLite</h1>
22

3-
<h3 align="center">Fast SQLite for react-native.</h3>
3+
<h3 align="center">Fast SQLite for React-Native.</h3>
44

5-
![Frame 2](https://user-images.githubusercontent.com/1634213/127499575-aed1d0e2-8a93-42ab-917e-badaab8916f6.png)
5+
![screenshot](https://raw.githubusercontent.com/ospfranco/react-native-quick-sqlite/main/header.png)
66

77
<div align="center">
88
<pre align="center">
@@ -21,7 +21,7 @@
2121
</div>
2222
<br />
2323

24-
This library uses [JSI](https://formidable.com/blog/2019/jsi-jsc-part-2) to directly call C++ code from JS. It provides a low-level API to execute SQL queries, therefore I recommend you use it with TypeORM.
24+
This library provides a low-level API to execute SQL queries, fast bindings via [JSI](https://formidable.com/blog/2019/jsi-jsc-part-2).
2525

2626
Inspired/compatible with [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) and [react-native-sqlite2](https://github.com/craftzdog/react-native-sqlite-2).
2727

@@ -30,15 +30,9 @@ Inspired/compatible with [react-native-sqlite-storage](https://github.com/andpor
3030
- **Javascript cannot represent intergers larger than 53 bits**, be careful when loading data if it came from other systems. [Read more](https://github.com/ospfranco/react-native-quick-sqlite/issues/16#issuecomment-1018412991).
3131
- **It's not possible to use a browser to debug a JSI app**, use [Flipper](https://github.com/facebook/flipper) (for android Flipper also has SQLite Database explorer).
3232
- Your app will now include C++, you will need to install the NDK on your machine for android.
33-
- This library supports SQLite BLOBs which are mapped to JS ArrayBuffers, check out the sample project on how to use it
34-
- From version 2.0.0 onwards errors are no longer thrown on invalid SQL statements. The response contains a `status` number, `0` signals correct execution, `1` signals an error.
35-
- From version 3.0.0 onwards no JS errors are thown, every operation returns an object with a `status` field.
36-
- On older react-native versions you might face weird NDK/SDK/Cmake errors, the latest version is tested against RN 0.67.3
3733

3834
## API
3935

40-
It is also possible to directly execute SQL against the db:
41-
4236
```typescript
4337
interface QueryResult {
4438
status: 0 | 1; // 0 for correct execution
@@ -54,33 +48,41 @@ interface BatchQueryResult {
5448
}
5549

5650
interface ISQLite {
57-
open: (dbName: string, location?: string) => any;
58-
59-
close: (dbName: string) => any;
60-
51+
open: (dbName: string, location?: string) => { status: 0 | 1 };
52+
close: (dbName: string) => { status: 0 | 1 };
6153
executeSql: (
6254
dbName: string,
6355
query: string,
6456
params: any[] | undefined
6557
) => QueryResult;
66-
6758
asyncExecuteSql: (
6859
dbName: string,
6960
query: string,
70-
params: any[] | undefined
71-
) => Promise<QueryResult>;
72-
61+
params: any[] | undefined,
62+
cb: (res: QueryResult) => void
63+
) => void;
7364
executeSqlBatch: (
7465
dbName: string,
7566
commands: SQLBatchParams[]
7667
) => BatchQueryResult;
68+
asyncExecuteSqlBatch: (
69+
dbName: string,
70+
commands: SQLBatchParams[],
71+
cb: (res: BatchQueryResult) => void
72+
) => void;
73+
loadSqlFile: (dbName: string, location: string) => FileLoadResult;
74+
asyncLoadSqlFile: (
75+
dbName: string,
76+
location: string,
77+
cb: (res: FileLoadResult) => void
78+
) => void;
7779
}
7880
```
7981

8082
# Usage
8183

8284
```typescript
83-
// You need to import this once in your app, it installs the binding on android
85+
// Import as early as possible, auto-installs bindings
8486
import 'react-native-quick-sqlite';
8587

8688
// `sqlite` is a globally registered object, so you can directly call it from anywhere in your javascript
@@ -132,15 +134,25 @@ if (!result.status) {
132134
}
133135
```
134136

137+
Async versions are also available if you have too much SQL to execute
138+
139+
```ts
140+
sqlite.asyncExecuteSql('myDatabase', 'SELECT * FROM "User";', [], (result) => {
141+
if (result.status === 0) {
142+
console.log('users', result.rows);
143+
}
144+
});
145+
```
146+
135147
## Use TypeORM
136148

137149
This package offers a low-level API to raw execute SQL queries. I strongly recommend to use [TypeORM](https://github.com/typeorm/typeorm) (with [patch-package](https://github.com/ds300/patch-package)). TypeORM already has a sqlite-storage driver. In the `example` project on the `patch` folder you can a find a [patch for TypeORM](https://github.com/ospfranco/react-native-quick-sqlite/blob/main/example/patches/typeorm%2B0.2.31.patch).
138150

139-
Follow the instructions to make TypeORM work with React Native (enable decorators, configure babel, etc), then apply the patch via patch-package and you should be good to go.
151+
Follow the instructions to make TypeORM work with React Native (enable decorators, configure babel, etc), then apply the example patch via patch-package.
140152

141153
## Learn React Native JSI
142154

143-
If you want to learn how to make your own JSI module buy my [JSI/C++ Cheatsheet](http://ospfranco.gumroad.com/l/IeeIvl), I'm also available for [freelance work](mailto:ospfranco@protonmail.com?subject=Freelance)!
155+
If you want to learn how to make your own JSI module buy my [JSI/C++ Cheatsheet](http://ospfranco.gumroad.com/l/jsi_guide), I'm also available for [freelance work](mailto:ospfranco@protonmail.com?subject=Freelance)!
144156

145157
## License
146158

header.png

173 KB
Loading

0 commit comments

Comments
 (0)