Skip to content

Commit 5be1158

Browse files
author
Oscar Franco
committed
Update readme to use imported module
1 parent dffc981 commit 5be1158

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,13 @@ openDatabase(
135135

136136
# Usage
137137

138-
Import as early as possible, auto-installs bindings in a thread-safe manner.
138+
Just import the package and fire away
139139

140140
```typescript
141141
// Thanks to @mrousavy for this installation method, see one example: https://github.com/mrousavy/react-native-mmkv/blob/75b425db530e26cf10c7054308583d03ff01851f/src/createMMKV.ts#L56
142-
import 'react-native-quick-sqlite';
142+
import { QuickSQLite } from 'react-native-quick-sqlite';
143143

144-
// Afterwards `sqlite` is a globally registered object, so you can directly call it from anywhere in your javascript
145-
const dbOpenResult = sqlite.open('myDatabase', 'databases');
144+
const dbOpenResult = QuickSQLite.open('myDatabase', 'databases');
146145

147146
// status === 1, operation failed
148147
if (dbOpenResult.status) {
@@ -155,7 +154,7 @@ if (dbOpenResult.status) {
155154
The basic query is **synchronous**, it will block rendering on large operations, below there are async versions.
156155

157156
```typescript
158-
let { status, rows } = sqlite.executeSql(
157+
let { status, rows } = QuickSQLite.executeSql(
159158
'myDatabase',
160159
'SELECT somevalue FROM sometable'
161160
);
@@ -165,7 +164,7 @@ if (!status) {
165164
});
166165
}
167166

168-
let { status, rowsAffected } = sqlite.executeSql(
167+
let { status, rowsAffected } = QuickSQLite.executeSql(
169168
'myDatabase',
170169
'UPDATE sometable SET somecolumn = ? where somekey = ?',
171170
[0, 1]
@@ -182,7 +181,7 @@ Transactions are supported. However, due to the library being opinionated and mo
182181
JSI bindings are fast but there is still some overhead calling `executeSql` for single queries, if you want to execute a large set of commands as fast as possible you should use the `executeSqlBatch` method below, it still uses transactions, but only transmits data between JS and native once.
183182

184183
```typescript
185-
sqlite.transaction('myDatabase', (tx) => {
184+
QuickSQLite.transaction('myDatabase', (tx) => {
186185
const {
187186
status,
188187
} = tx.executeSql('UPDATE sometable SET somecolumn = ? where somekey = ?', [
@@ -209,7 +208,7 @@ const commands = [
209208
('INSERT INTO TABLE TEST (id) VALUES (?)', [2])
210209
][('INSERT INTO TABLE TEST (id) VALUES (?)', [[3], [4], [5], [6]])],
211210
];
212-
const result = sqlite.executeSqlBatch('myDatabase', commands);
211+
const result = QuickSQLite.executeSqlBatch('myDatabase', commands);
213212
if (!result.status) {
214213
// result.status undefined or 0 === success
215214
console.log(`Batch affected ${result.rowsAffected} rows`);
@@ -225,7 +224,7 @@ sqlite datatypes. When fetching data directly from tables or views linked to tab
225224
to identify the table declared types:
226225

227226
```typescript
228-
let { status, metadata } = sqlite.executeSql(
227+
let { status, metadata } = QuickSQLite.executeSql(
229228
'myDatabase',
230229
'SELECT int_column_1, bol_column_2 FROM sometable'
231230
);
@@ -244,7 +243,7 @@ if (!status) {
244243
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.
245244

246245
```ts
247-
sqlite.asyncExecuteSql(
246+
QuickSQLite.asyncExecuteSql(
248247
'myDatabase',
249248
'SELECT * FROM "User";',
250249
[],
@@ -270,21 +269,29 @@ SQLite have a limit for attached databases: A default of 10, and a global max of
270269
References: [Attach](https://www.sqlite.org/lang_attach.html) - [Detach](https://www.sqlite.org/lang_detach.html)
271270

272271
```ts
273-
const result = sqlite.attach('mainDatabase', 'statistics', 'stats', '../databases',);
272+
const result = QuickSQLite.attach(
273+
'mainDatabase',
274+
'statistics',
275+
'stats',
276+
'../databases'
277+
);
274278

275279
// Database is attached sucefully
276-
if(!result.status) {
277-
const data = sqlite.executeSql('mainDatabase', 'SELECT * FROM some_table_from_mainschema a INNER JOIN stats.some_table b on a.id_column = b.id_column');
280+
if (!result.status) {
281+
const data = QuickSQLite.executeSql(
282+
'mainDatabase',
283+
'SELECT * FROM some_table_from_mainschema a INNER JOIN stats.some_table b on a.id_column = b.id_column'
284+
);
278285
// Consume the results
279-
if(!data.status) {}
286+
if (!data.status) {
287+
}
280288
}
281289

282290
// You can detach databases at any moment
283-
const detachResult = sqlite.detach('mainDatabase', 'stats');
284-
if(!detachResult.status) {
291+
const detachResult = QuickSQLite.detach('mainDatabase', 'stats');
292+
if (!detachResult.status) {
285293
// Database dettached
286294
}
287-
288295
```
289296

290297
## Use built-in SQLite

0 commit comments

Comments
 (0)