NitroSQLite
API Reference / react-native-nitro-sqlite / NitroSQLite
Variable: NitroSQLite
constNitroSQLite:object
Database entry point. Prefer open for a managed connection.
native exposes the Nitro object directly and bypasses the JavaScript queue.
Type Declaration
execute
execute: <
Row>(dbName,query,params?) =>QueryResult<Row>
Execute one SQL statement synchronously by database name. Uses the managed queue when the database has an open managed connection.
Type Parameters
Row
Row extends QueryResultRow = never
Parameters
dbName
string
Name of an open native database.
query
string
SQL statement with optional positional placeholders.
params?
Values bound to the placeholders.
Returns
QueryResult<Row>
The query result with typed rows.
executeAsync
executeAsync: <
Row>(dbName,query,params?) =>Promise<QueryResult<Row>>
Execute one SQL statement asynchronously by database name. Uses the managed queue when the database has an open managed connection.
Type Parameters
Row
Row extends QueryResultRow = never
Parameters
dbName
string
Name of an open native database.
query
string
SQL statement with optional positional placeholders.
params?
Values bound to the placeholders.
Returns
Promise<QueryResult<Row>>
A promise of the query result with typed rows.
executeBatch
executeBatch: (
dbName,commands) =>BatchQueryResult
Execute a batch synchronously in one exclusive transaction. Requires an open managed connection; throws if it is busy or the batch is empty.
Parameters
dbName
string
Name of the open database.
commands
SQL commands and optional parameter sets.
Returns
Total affected row count.
executeBatchAsync
executeBatchAsync: (
dbName,commands) =>Promise<BatchQueryResult>
Queue a batch in one exclusive transaction. Requires an open managed connection; a failed command rolls back the batch.
Parameters
dbName
string
Name of the open database.
commands
SQL commands and optional parameter sets.
Returns
Promise<BatchQueryResult>
A promise of the total affected row count.
native
native:
NitroSQLite=HybridNitroSQLite
open
open: (
options) =>NitroSQLiteConnection
Open or create a database and return a managed connection. Async calls on that connection run in call order. A second managed connection with the same name throws until the first is closed or deleted.
Parameters
options
Database name and optional directory relative to the platform database directory.
Returns
A connection bound to the named database.
transaction
transaction: <
Result>(dbName,transactionCallback,isExclusive) =>Promise<Result>
Queue a transaction for an open managed connection.
Use only the supplied tx for work on this database inside the callback.
A successful callback commits unless it explicitly committed or rolled back;
a thrown error rolls back unless the transaction was already finalized.
Type Parameters
Result
Result = void
Parameters
dbName
string
Name of the open database.
transactionCallback
(tx) => Promise<Result>
Async callback receiving the transaction handle.
isExclusive?
boolean = false
Begin an exclusive transaction when true.
Returns
Promise<Result>
The callback's result after the transaction finishes.
attach()
attach(
mainDbName,dbNameToAttach,alias,location?):void
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
Close the named native database handle.
Parameters
dbName
string
Name of the open database.
Returns
void
detach()
detach(
mainDbName,alias):void
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?):void
Remove the named database file and close its native handle if open.
Parameters
dbName
string
Database file name.
location?
string
Directory relative to the platform database directory.
Returns
void
loadFile()
loadFile(
dbName,location):FileLoadResult
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.
loadFileAsync()
loadFileAsync(
dbName,location):Promise<FileLoadResult>
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.