NativeSQLite
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
NativeHybridObject
Methods
attach()
attach(mainDbName, dbNameToAttach, alias, location?): void
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:103
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:88
Close a default connection by name or an independent connection by ID.
Parameters
dbName
string
Returns
void
detach()
detach(mainDbName, alias): void
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:113
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:95
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?, requireTransaction?): NativeQueryResultBinding
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:124
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?
Positional values bound to SQL placeholders.
requireTransaction?
boolean
Reject before executing SQL if SQLite is in autocommit mode. The check runs under the connection lock, including for queued background calls. Omit for normal execution, including manual BEGIN, COMMIT, and ROLLBACK.
Returns
Native query rows, affected row count, insert ID, and metadata.
Throws
If the connection is closed or a required transaction has ended.
executeAsync()
executeAsync(dbName, query, params?, onRows?, rowBatchId?, requireTransaction?): Promise<NativeQueryResultBinding>
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:147
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?
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.
requireTransaction?
boolean
Reject before executing SQL if SQLite is in autocommit mode. The check runs under the connection lock, including for queued background calls. Omit for normal execution, including manual BEGIN, COMMIT, and ROLLBACK.
Returns
Promise<NativeQueryResultBinding>
A promise of the native query result.
Throws
If the connection is closed or a required transaction has ended.
executeBatch()
executeBatch(dbName, commands): BatchQueryResult
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:225
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
SQL commands and optional parameter sets.
Returns
Total affected row count.
executeBatchAsync()
executeBatchAsync(dbName, commands): Promise<BatchQueryResult>
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:232
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
SQL commands and optional parameter sets.
Returns
Promise<BatchQueryResult>
A promise of the total affected row count.
executeRaw()
executeRaw(dbName, query, params?, requireTransaction?): NativeRawQueryResult
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:190
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?
Positional values bound to SQL placeholders.
requireTransaction?
boolean
Reject before executing SQL if SQLite is in autocommit mode. The check runs under the connection lock, including for queued background calls. Omit for normal execution, including manual BEGIN, COMMIT, and ROLLBACK.
Returns
Column names, rows as value arrays, affected row count, and insert ID.
Throws
If the connection is closed or a required transaction has ended.
executeRawAsync()
executeRawAsync(dbName, query, params?, requireTransaction?): Promise<NativeRawQueryResult>
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:206
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?
Positional values bound to SQL placeholders.
requireTransaction?
boolean
Reject before executing SQL if SQLite is in autocommit mode. The check runs under the connection lock, including for queued background calls. Omit for normal execution, including manual BEGIN, COMMIT, and ROLLBACK.
Returns
Promise<NativeRawQueryResult>
A promise of the native raw query result.
Throws
If the connection is closed or a required transaction has ended.
isConnectionOpen()
isConnectionOpen(connectionId): boolean
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:86
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:245
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
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:253
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:60
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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:77
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): NativePreparedStatement
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:218
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
A native statement with synchronous and asynchronous execution methods.
setChangeHandler()
setChangeHandler(dbName, handler?): void
Defined in: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:176
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. A replacement handler receives only changes recorded after it was set. 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: packages/react-native-nitro-sqlite/src/specs/NitroSQLite.nitro.ts:164
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. A query's next batch is posted to the JS thread only after the handler has returned
for the previous one, so frames and other JavaScript work can run between batches. If the query
fails, batches that were not posted yet are dropped.
Returns
void