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
db.close(); //closes all connections, finalizes all prepared statements
135
+
db.isOpen; // boolean
136
+
awaitdb.close(); //waits for in-flight operations to finish, then closes all connections
121
137
```
122
138
139
+
`close()` is async — it waits for all queued operations on the writer and reader queues to drain, rolls back any active write transaction, finalizes prepared statements, and rejects any pending queued transactions. The returned Promise resolves when everything is fully shut down.
140
+
123
141
### Parameters
124
142
125
143
Both positional and named parameters are supported.
@@ -155,7 +173,7 @@ The prefix (`:`, `$`, `@`) is added automatically if omitted — you can pass `{
155
173
156
174
#### Write Transactions
157
175
158
-
Write transactions use the writer connection with `BEGINIMMEDIATE`, ensuring an exclusive write lock from the start. They are serialized — concurrent calls to `transaction()` will queue automatically.
176
+
Write transactions use `BEGINDEFERRED` by default. They are serialized through a transaction queue — concurrent calls to `transaction()`are safe and will wait their turn automatically.
If the callback throws, the transaction is rolled back. If it completes normally, it is committed. The return value of the callback is forwarded to the caller.
170
188
171
-
**Concurrent transactions** are safe — the second transaction's `BEGINIMMEDIATE` queues behind the first's `COMMIT` on the writer's serial dispatch queue:
189
+
**Concurrent transactions** are safe — the second transaction waits for the first to finish before starting:
172
190
173
191
```typescript
174
-
// Both run, but writes are serialized
192
+
// Both run, but writes are serialized via the transaction queue
Prepared statements are automatically finalized when the database is closed, but it is good practice to finalize them explicitly when no longer needed.
232
250
233
-
### `selectArray` — Columnar Result Format
251
+
### `selectArray`/ `getArray`— Columnar Result Format
234
252
235
-
`selectArray`returns column names once and rows as arrays of values. This is more efficient for large result sets since column names are not repeated per row.
253
+
`selectArray`and `getArray` return column names once and rows as arrays of values. This is more efficient than `select`/`get` for large result sets since column names are not repeated per row.
constsingle=awaitdb.getArray('SELECT id, name FROM users WHERE id = ?', [1]);
267
+
// single.columns => ['id', 'name']
268
+
// single.rows => [[1, 'Alice']] (or [] if no match)
246
269
```
247
270
248
-
Available on all contexts: `db.selectArray()`, `db.selectArraySync()`, `tx.selectArray()`, `stmt.selectArray()`.
271
+
Available on all contexts: `db.selectArray()`, `db.getArray()`, `db.selectArraySync()`, `db.getArraySync()`, `tx.selectArray()`, `tx.getArray()`, `stmt.selectArray()`, `stmt.getArray()`.
249
272
250
273
### Error Handling
251
274
@@ -265,15 +288,58 @@ try {
265
288
}
266
289
```
267
290
291
+
### Low-Level Transaction Control
292
+
293
+
For driver integrations (e.g., drizzle), the database exposes `txId`-based methods that allow external transaction management:
The plugin opens multiple SQLite connections to the same database file:
273
338
274
339
-**1writerconnection** — openedwith`SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE`. Allwrites (`execute`, writetransactions) dispatchtoaserialGCDqueue, ensuring only one write happens at a time.
275
-
- **N reader connections** — opened with `SQLITE_OPEN_READONLY`. Reads (`select`, `get`) are distributed across readers via round-robin, each with its own serial GCD queue. Multiple reads can run concurrently on different readers.
340
+
- **N reader connections** — opened with `SQLITE_OPEN_READWRITE` + `PRAGMA query_only=ON`. Reads (`select`, `get`) are distributed across readers via round-robin, each with its own serial GCD queue. Multiple reads can run concurrently on different readers. Readers open as READWRITE so they can initialize WAL shared memory, but `query_only` prevents accidental writes.
276
341
- **1 sync connection** — opened lazily on the first sync call. Used exclusively by `executeSync`/`selectSync`/`getSync` on the main thread.
342
+
- **Transaction queue** — concurrent `transaction()` calls are queued. The next transaction's `BEGIN` only dispatches after the previous one commits or rolls back.
277
343
278
344
WAL (Write-Ahead Logging) mode is enabled automatically on the writer. WAL allows readers to proceed without blocking writes, and writes to proceed without blocking readers.
279
345
@@ -282,24 +348,50 @@ WAL (Write-Ahead Logging) mode is enabled automatically on the writer. WAL allow
282
348
- All SQLite work (prepare, bind, step, column extraction) happens on background GCD threads.
283
349
- Results are serialized to a JSON string on the background thread. Only one value (the string) crosses the native-to-JS bridge. `JSON.parse` in V8 is highly optimized native C++ code.
284
350
- Blob columns are returned as separate `NSData` objects and converted to `ArrayBuffer` via `interop.bufferFromData` (noextracopy).
285
-
- The `selectArray` format avoids repeating column names per row, reducing both serialization cost and memory usage for large result sets.
351
+
- The `selectArray` / `getArray` format avoids repeating column names per row, reducing both serialization cost and memory usage for large result sets.
352
+
353
+
## SQLite Linking
354
+
355
+
The plugin does **not** bundle or link a SQLite library — you must provide one. This gives you full control over the SQLite version and features available. Add **one** of the following to your app:
By default, the plugin links against the system `libsqlite3` shipped with iOS. This SQLite version may lack features like the recovery extension, FTS5 tokenizer customization, or other compile-time options.
2.Thepod's symbols will override the system SQLite at link time. No plugin code changes are needed — it calls the same C API functions regardless of the underlying implementation.
375
+
OruseyourownpodspecpointingtoacustomSQLitebuild. Thepod's sqlite3 symbols replace the system ones at link time. No plugin code changes needed.
0 commit comments