NitroSQLite
react-native-nitro-sqliteHybrid Objects

NitroSQLiteNative

TypeScriptC++

Source files: TypeScript · C++

Native database operations exposed through NitroSQLite.native. These calls bypass the managed connection queue. Coordinate them with any transaction or pending operation on the same database yourself.

Extends

  • HybridObject<{ android: "c++"; ios: "c++"; }>

Methods

attach()

attach(mainDbName, dbNameToAttach, alias, location?): void

Defined in: specs/NitroSQLite.nitro.ts:76

Attach a database file to an open main database under an SQL schema alias.

Parameters

mainDbName

string

Name of the open main database.

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(dbName): void

Defined in: specs/NitroSQLite.nitro.ts:61

Close a default connection by name or an independent connection by ID.

Parameters

dbName

string

Returns

void


detach()

detach(mainDbName, alias): void

Defined in: specs/NitroSQLite.nitro.ts:86

Detach an attached database by its alias.

Parameters

mainDbName

string

Name of the open main database.

alias

string

SQL schema name used when attaching.

Returns

void


drop()

drop(dbName, location?, connectionId?): void

Defined in: specs/NitroSQLite.nitro.ts:68

Delete a database and close the indicated connection if open. Deletion fails while another connection or attachment uses the database file.

Parameters

dbName

string

Database file name.

location?

string

Directory relative to the platform database directory.

connectionId?

string

Optional ID of the independent connection to close.

Returns

void


execute()

execute(dbName, query, params?): NitroSQLiteQueryResult

Defined in: specs/NitroSQLite.nitro.ts:93

Execute one SQL statement synchronously on the calling thread.

Parameters

dbName

string

Name of an open database.

query

string

SQL statement with optional positional placeholders.

params?

SQLiteQueryParams

Positional values bound to SQL placeholders.

Returns

NitroSQLiteQueryResult

Native query rows, affected row count, insert ID, and metadata.


executeAsync()

executeAsync(dbName, query, params?, onRows?, rowBatchId?): Promise<NitroSQLiteQueryResult>

Defined in: specs/NitroSQLite.nitro.ts:111

Execute one SQL statement on a background thread.

Parameters

dbName

string

Name of an open database.

query

string

SQL statement with optional positional placeholders.

params?

SQLiteQueryParams

Positional values bound to SQL placeholders.

onRows?

(rows) => void

Receives leading rows in batches, in order, while SQLite still reads the rest, so JavaScript can convert a batch while the next one is read. Batched rows are not repeated in the result's results, which then holds only the rows after the last batch. The promise can settle before the last batches arrive, so wait until batchedRowCount rows have arrived.

rowBatchId?

number

Without onRows, sends the same batches to the handler set with setRowBatchHandler, tagged with this ID. Unlike onRows, no function crosses to native code for each query.

Returns

Promise<NitroSQLiteQueryResult>

A promise of the native query result.


executeBatch()

executeBatch(dbName, commands): BatchQueryResult

Defined in: specs/NitroSQLite.nitro.ts:175

Execute commands in one exclusive transaction on the calling thread. An empty batch throws; a failed command rolls back the batch.

Parameters

dbName

string

Name of an open database.

commands

BatchQueryCommand[]

SQL commands and optional parameter sets.

Returns

BatchQueryResult

Total affected row count.


executeBatchAsync()

executeBatchAsync(dbName, commands): Promise<BatchQueryResult>

Defined in: specs/NitroSQLite.nitro.ts:182

Execute commands in one exclusive transaction on a background thread. An empty batch rejects; a failed command rolls back the batch.

Parameters

dbName

string

Name of an open database.

commands

BatchQueryCommand[]

SQL commands and optional parameter sets.

Returns

Promise<BatchQueryResult>

A promise of the total affected row count.


executeRaw()

executeRaw(dbName, query, params?): NitroSQLiteRawQueryResult

Defined in: specs/NitroSQLite.nitro.ts:146

Execute one SQL statement synchronously on the calling thread, returning rows as arrays of column values.

Parameters

dbName

string

Name of an open database.

query

string

SQL statement with optional positional placeholders.

params?

SQLiteQueryParams

Positional values bound to SQL placeholders.

Returns

NitroSQLiteRawQueryResult

Column names, rows as value arrays, affected row count, and insert ID.


executeRawAsync()

executeRawAsync(dbName, query, params?): Promise<NitroSQLiteRawQueryResult>

Defined in: specs/NitroSQLite.nitro.ts:157

Execute one SQL statement on a background thread, returning rows as arrays of column values.

Parameters

dbName

string

Name of an open database.

query

string

SQL statement with optional positional placeholders.

params?

SQLiteQueryParams

Positional values bound to SQL placeholders.

Returns

Promise<NitroSQLiteRawQueryResult>

A promise of the native raw query result.


isConnectionOpen()

isConnectionOpen(connectionId): boolean

Defined in: specs/NitroSQLite.nitro.ts:59

Check whether a native connection ID is still open.

Parameters

connectionId

string

ID returned by openConnection.

Returns

boolean


loadFile()

loadFile(dbName, location): FileLoadResult

Defined in: specs/NitroSQLite.nitro.ts:195

Import a SQL file in one exclusive transaction on the calling thread. Each non-empty line is treated as one statement.

Parameters

dbName

string

Name of an open database.

location

string

Path to the SQL file.

Returns

FileLoadResult

Number of executed commands and affected rows.

Throws

An Error with native category CouldNotLoadFile on an import failure, including the path, failing SQL/line, and any rollback failure. Completed commands are discarded when rollback succeeds.


loadFileAsync()

loadFileAsync(dbName, location): Promise<FileLoadResult>

Defined in: specs/NitroSQLite.nitro.ts:203

Import a SQL file on a background thread.

Parameters

dbName

string

Name of an open database.

location

string

Path to the SQL file.

Returns

Promise<FileLoadResult>

A promise of the command and affected row counts.

Throws

An Error with native category CouldNotLoadFile, preserving the original import error and any rollback failure. Rejects asynchronously.


open()

open(dbName, location?, readOnly?, encryptionKey?): void

Defined in: specs/NitroSQLite.nitro.ts:33

Open a name-based default connection, creating the database unless readOnly is true.

Parameters

dbName

string

Database file name and default connection key.

location?

string

Directory relative to the platform database directory.

readOnly?

boolean

Open an existing database without write access.

encryptionKey?

string

Optional key for a licensed SEE build. Without SEE, a supplied key throws EncryptionNotEnabled. An invalid or wrong key or an existing plaintext database throws DatabaseCannotBeDecrypted.

Returns

void


openConnection()

openConnection(dbName, location?, readOnly?, encryptionKey?): string

Defined in: specs/NitroSQLite.nitro.ts:50

Open a separate native handle, even when the database file is already open. Independent connections require a thread-safe SQLite build.

Parameters

dbName

string

Database file name.

location?

string

Directory relative to the platform database directory.

readOnly?

boolean

Open an existing database without write access.

encryptionKey?

string

Optional SEE key for this handle. Supply the same key on every connection to an encrypted file. Without SEE, a supplied key throws EncryptionNotEnabled. An invalid or wrong key or an existing plaintext database throws DatabaseCannotBeDecrypted.

Returns

string

An opaque ID to pass to native connection operations.


prepare()

prepare(dbName, query): NitroSQLitePreparedStatement

Defined in: specs/NitroSQLite.nitro.ts:168

Prepare one SQL statement on an open native connection for repeated execution. Finalize the returned statement before closing its connection.

Parameters

dbName

string

Name or ID of an open database connection.

query

string

SQL statement with optional positional placeholders.

Returns

NitroSQLitePreparedStatement

A native statement with synchronous and asynchronous execution methods.


setChangeHandler()

setChangeHandler(dbName, handler?): void

Defined in: specs/NitroSQLite.nitro.ts:136

Report committed row changes on a connection, or stop reporting them. While a handler is set, SQLite's update hook records each inserted, updated, or deleted row. A rollback discards the recorded changes, and so does a statement that throws. Once no transaction is open, the handler receives the recorded changes, asynchronously on the JS thread. Closing the connection removes the handler.

Parameters

dbName

string

Name or ID of an open database connection.

handler?

(changes) => void

Receives each batch of committed changes. Omit it to stop reporting changes.

Returns

void


setRowBatchHandler()

setRowBatchHandler(handler): void

Defined in: specs/NitroSQLite.nitro.ts:125

Set the function that receives row batches for executeAsync calls made with a rowBatchId. The managed API sets it on its first async query and relies on it, so replacing it leaves managed async queries with batched rows waiting for rows that never arrive.

Parameters

handler

(rowBatchId, rows) => void

Receives the query's row batch ID and its next batch of leading rows, in order. Batches can arrive after the query's promise settles; its batchedRowCount says how many rows to expect.

Returns

void