NitroSQLite

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

Interface: NitroSQLiteNative

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

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


execute()

execute(dbName, query, params?): NitroSQLiteQueryResult

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?): Promise<NitroSQLiteQueryResult>

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.

Returns

Promise<NitroSQLiteQueryResult>

A promise of the native query result.


executeBatch()

executeBatch(dbName, commands): BatchQueryResult

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>

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.


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

FileLoadResult

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.


open()

open(dbName, location?): void

Open or create a database synchronously.

Parameters

dbName

string

Database file name.

location?

string

Directory relative to the platform database directory.

Returns

void