NitroSQLite

API Reference / react-native-nitro-sqlite / NitroSQLiteConnection

Interface: NitroSQLiteConnection

A managed connection bound to one database name. Do not use it after closing or deleting it.

Properties

execute

execute: ExecuteQuery

Execute one SQL statement synchronously. Throws while the connection is busy.


executeAsync

executeAsync: ExecuteAsyncQuery

Queue one SQL statement and resolve with its result.


transaction

transaction: <Result>(transactionCallback) => Promise<Result>

Run a callback in a queued transaction. The callback must use tx for database work. It commits on success and rolls back on error unless explicitly finalized. Awaiting another queued operation for this database inside the callback deadlocks. Synchronous connection methods throw while this transaction is active.

Type Parameters

Result

Result = void

Parameters

transactionCallback

(tx) => Promise<Result>

Async callback receiving the transaction handle.

Returns

Promise<Result>

The callback's result after the transaction finishes.

Methods

attach()

attach(dbNameToAttach, alias, location?): void

Attach another database under alias for queries against this connection.

Parameters

dbNameToAttach

string

File name of the database to attach.

alias

string

SQL schema name for the attached database.

location?

string

Directory relative to the platform database directory.

Returns

void


close()

close(): void

Close the connection. Throws if a queued operation is running or pending.

Returns

void


delete()

delete(): void

Delete the database file and end this connection. Throws if the connection is busy. This also closes the native handle if it is open.

Returns

void


detach()

detach(alias): void

Detach the database identified by alias.

Parameters

alias

string

SQL schema name used when attaching the database.

Returns

void


executeBatch()

executeBatch(commands): BatchQueryResult

Execute commands in one exclusive transaction. Throws while the connection is busy.

Parameters

commands

BatchQueryCommand[]

SQL commands and optional parameter sets.

Returns

BatchQueryResult

Total affected row count.


executeBatchAsync()

executeBatchAsync(commands): Promise<BatchQueryResult>

Queue commands in one exclusive transaction.

Parameters

commands

BatchQueryCommand[]

SQL commands and optional parameter sets.

Returns

Promise<BatchQueryResult>

A promise of the total affected row count.


loadFile()

loadFile(location): FileLoadResult

Execute one non-empty SQL command per file line in an exclusive transaction. location is a path to the SQL file; multi-line statements are unsupported.

Parameters

location

string

Path to the SQL file.

Returns

FileLoadResult

Number of executed commands and affected rows.


loadFileAsync()

loadFileAsync(location): Promise<FileLoadResult>

Queue the file import and resolve with its command and row counts.

Parameters

location

string

Path to the SQL file.

Returns

Promise<FileLoadResult>