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
Quick SQLite uses [JSI](https://formidable.com/blog/2019/jsi-jsc-part-2), removes all the overhead of intercommunication between JavaScript code and C++ code, making CRUDing entities from SQLite super fast!
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.
25
25
26
-
Big ❤️ to [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) and [react-native-sqlite2](https://github.com/craftzdog/react-native-sqlite-2), this library also provides a WebSQL interface.
26
+
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).
27
27
28
-
If you are using quick-sqlite in your app, please get in touch or open a PR with a modified README (with your company/product logo, would love to showcase you!
28
+
## Gotchas
29
29
30
-
## GOTCHAS
31
-
32
-
-**It's not possible to use the browser debugger with JSI**, use [Flipper](https://github.com/facebook/flipper), on android Flipper also has an integrated database explorer you can use to debug your sqlite database, [you will have to configure your database path though](https://fbflipper.com/docs/setup/plugins/databases/).
- Your app will now include C++, you will need to install the NDK on your machine for android. (unless you know how to generate an AAR, feel free to open a PR)
35
-
- If you want to run the example project on android, you will have to change the paths on the android/CMakeLists.txt file, they are already there, just uncomment them.
30
+
-**It's not possible to use a browser to debug a JSI app**, use [Flipper](https://github.com/facebook/flipper) (on android Flipper also has an integrated SQLite Database explorer).
31
+
- Your app will now include C++, you will need to install the NDK on your machine for android.
36
32
- This library supports SQLite BLOBs which are mapped to JS ArrayBuffers, check out the sample project on how to use it
37
-
- Starting with version 2.0.0 the library no longer throws errors when an invalid statement is passed, but rather returns an object with a `status` enum property, where 0 signals a succesful execution and `1` an incorrect execution (this is to keep typeorm from exploding when an incorrect query is executed)
38
-
- This library cannot retrieve integers larger than 53 bits because it's not possible to represent such numbers in JavaScript. [Read here](https://github.com/ospfranco/react-native-quick-sqlite/issues/16#issuecomment-1018412991) for more information.
33
+
- If you want to run the example project on android, you will have to change the paths on the android/CMakeLists.txt file, they are already there, just uncomment them.
34
+
- Starting with version 2.0.0 the library no longer throws errors when an invalid statement is passed, but returns a status (0 or 1) field in the response.
35
+
- This library cannot retrieve integers larger than 53 bits because it's not possible to represent such numbers in JavaScript. [Read more](https://github.com/ospfranco/react-native-quick-sqlite/issues/16#issuecomment-1018412991).
39
36
40
37
## Use TypeORM
41
38
42
-
The recommended way to use this package is 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), it basically just replaces all the `react-native-sqlite-storage` strings in TypeORM with `react-native-quick-sqlite`.
39
+
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).
43
40
44
-
Follow the instructions to make TypeORM work with rn (enable decorators, configure babel, etc), then apply the patch via patch-package and you should be good to go.
41
+
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.
45
42
46
-
## Low level API
43
+
## API
47
44
48
45
It is also possible to directly execute SQL against the db:
49
46
50
47
```typescript
48
+
interfaceQueryResult {
49
+
status:0|1; // 0 for correct execution
50
+
message:string; // if status === 1, here you will find error description
51
+
rows:any[];
52
+
insertId?:number;
53
+
}
54
+
55
+
interfaceBatchQueryResult {
56
+
status?:0|1;
57
+
rowsAffected?:number;
58
+
message?:string;
59
+
}
60
+
51
61
interfaceISQLite {
52
62
open: (dbName:string, location?:string) =>any;
53
63
close: (dbName:string) =>any;
@@ -59,7 +69,7 @@ interface ISQLite {
59
69
executeSqlBatch: (
60
70
dbName:string,
61
71
commands:SQLBatchParams[]
62
-
) =>BatchExecutionResult;
72
+
) =>BatchQueryResult;
63
73
}
64
74
```
65
75
@@ -79,36 +89,45 @@ try {
79
89
```
80
90
81
91
Some query examples:
92
+
82
93
```typescript
83
94
let result =sqlite.executeSql('myDatabase', 'SELECT somevalue FROM sometable');
84
-
if(!result.status) { // result.status undefined or 0 === sucess
85
-
for(let i =0; i<result.rows.length; i++) {
95
+
if (!result.status) {
96
+
// result.status undefined or 0 === sucess
97
+
for (let i =0; i<result.rows.length; i++) {
86
98
const row =result.rows.item(i);
87
99
console.log(row.somevalue);
88
100
}
89
101
}
90
102
91
-
result=sqlite.executeSql('myDatabase', 'UPDATE sometable set somecolumn = ? where somekey = ?', [0, 1]);
92
-
if(!result.status) { // result.status undefined or 0 === sucess
103
+
result=sqlite.executeSql(
104
+
'myDatabase',
105
+
'UPDATE sometable set somecolumn = ? where somekey = ?',
If you want to learn how to make your own JSI module and also get a reference guide for all things C++/JSI you can buy my [JSI/C++ Cheatsheet](http://ospfranco.gumroad.com/l/IeeIvl)
0 commit comments