@@ -185,12 +185,18 @@ type SqlValue = string | number | boolean | null | Uint8Array
185185Supported SQLite types:
186186
187187 * **TEXT** - ` string ` values (also used for DATE, TIME, DATETIME)
188- * **INTEGER** - ` number ` values (integers)
188+ * **INTEGER** - ` number ` values (integers, preserved up to i64 range )
189189 * **REAL** - ` number ` values (floating point)
190190 * **BOOLEAN** - ` boolean ` values
191191 * **NULL** - ` null ` value
192192 * **BLOB** - ` Uint8Array ` for binary data
193193
194+ > **Note:** JavaScript's ` number ` type can safely represent integers up to
195+ > ±2^53 - 1 (±9,007,199,254,740,991). The plugin preserves integer precision by
196+ > binding integers as SQLite's INTEGER type (i64). For values within the i64
197+ > range (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807), full precision
198+ > is maintained. Values outside this range may lose precision.
199+
194200` ` ` typescript
195201// Example with different types
196202await db .execute (
@@ -265,7 +271,6 @@ Common error codes include:
265271 * ` INVALID_PATH ` - Invalid database path
266272 * ` IO_ERROR ` - File system error
267273 * ` MIGRATION_ERROR ` - Migration failed
268- * ` READ_ONLY_QUERY_IN_EXECUTE ` - Attempted to use execute() for a read-only query
269274 * ` MULTIPLE_ROWS_RETURNED ` - ` fetchOne() ` query returned multiple rows
270275
271276### Executing SELECT Queries
@@ -304,45 +309,35 @@ if (user) {
304309
305310### Using Transactions
306311
307- Transactions ensure that multiple operations either all succeed or all fail together,
308- maintaining data consistency:
312+ Execute multiple database operations atomically using ` executeTransaction() ` . All
313+ statements either succeed together or fail together, maintaining data consistency:
309314
310315``` typescript
311- // Begin a transaction
312- await db .beginTransaction ();
313-
314- try {
315- // Execute multiple operations atomically
316- await db .execute (
317- ' INSERT INTO users (name, email) VALUES ($1, $2)' ,
318- [' Alice' , ' alice@example.com' ]
319- );
320-
321- await db .execute (
322- ' INSERT INTO audit_log (action, user) VALUES ($1, $2)' ,
323- [' user_created' , ' Alice' ]
324- );
325-
326- // Commit if all operations succeed
327- await db .commitTransaction ();
328- console .log (' Transaction completed successfully' );
329-
330- } catch (error ) {
331- // Rollback if any operation fails
332- await db .rollbackTransaction ();
333- console .error (' Transaction failed, rolled back:' , error );
334- throw error ;
335- }
336- ```
337-
338- ** Important Notes:**
339-
340- * All operations between ` beginTransaction() ` and
341- ` commitTransaction() ` /` rollbackTransaction() ` are executed as a single atomic unit
342- * If an error occurs, call ` rollbackTransaction() ` to discard all changes
343- * Nested transactions are not supported
344- * Always ensure transactions are either committed or rolled back to avoid locking
345- issues
316+ // Execute multiple inserts atomically
317+ const results = await db .executeTransaction ([
318+ [' INSERT INTO users (name, email) VALUES ($1, $2)' , [' Alice' , ' alice@example.com' ]],
319+ [' INSERT INTO audit_log (action, user) VALUES ($1, $2)' , [' user_created' , ' Alice' ]]
320+ ]);
321+ console .log (` User ID: ${results [0 ].lastInsertId } ` );
322+ console .log (` Log rows affected: ${results [1 ].rowsAffected } ` );
323+
324+ // Bank transfer example - all operations succeed or all fail
325+ const results = await db .executeTransaction ([
326+ [' UPDATE accounts SET balance = balance - $1 WHERE id = $2' , [100 , 1 ]],
327+ [' UPDATE accounts SET balance = balance + $1 WHERE id = $2' , [100 , 2 ]],
328+ [' INSERT INTO transfers (from_id, to_id, amount) VALUES ($1, $2, $3)' , [1 , 2 , 100 ]]
329+ ]);
330+ console .log (` Transfer ID: ${results [2 ].lastInsertId } ` );
331+ ```
332+
333+ ** How it works:**
334+
335+ * Automatically executes ` BEGIN ` before running statements
336+ * Executes all statements in order
337+ * Commits with ` COMMIT ` if all statements succeed
338+ * Rolls back with ` ROLLBACK ` if any statement fails
339+ * The write connection is held for the entire transaction, ensuring atomicity
340+ * Errors are thrown after rollback, preserving the original error message
346341
347342### Closing Connections
348343
@@ -465,8 +460,8 @@ const filtered = await db.fetchAll<User[]>(
465460)
466461```
467462
468- > ** Important :** Do NOT use ` execute ()` for read-only queries. It will return
469- > an error. Always use ` fetchAll() ` or ` fetchOne() ` for reads .
463+ > ** Note :** Use ` execute() ` and ` executeTransaction ()` for write operations.
464+ > For SELECT queries, use ` fetchAll() ` or ` fetchOne() ` .
470465
471466## Configuration
472467
@@ -541,7 +536,7 @@ await Database.closeAll()
541536
542537#### Instance Methods
543538
544- ##### ` execute(query: string, bindValues?: unknown[]): Promise<QueryResult > `
539+ ##### ` execute(query: string, bindValues?: unknown[]): Promise<WriteQueryResult > `
545540
546541Execute a write query (INSERT, UPDATE, DELETE, CREATE, etc.).
547542
@@ -602,9 +597,9 @@ await db.remove()
602597### TypeScript Interfaces
603598
604599``` typescript
605- interface QueryResult {
600+ interface WriteQueryResult {
606601 rowsAffected: number // Number of rows modified
607- lastInsertId: number // ROWID of last inserted row
602+ lastInsertId: number // ROWID of last inserted row (not set for WITHOUT ROWID tables, returns 0)
608603}
609604
610605interface CustomConfig {
0 commit comments