Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/ci-paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
".github/actions/**",
".github/ci-paths.json",
"scripts/ci*",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteDatabaseMigration.*",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteDatabaseConnections.*",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteExecuteBatch.*",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteOperations.*",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteStatementGroup.hpp",
"packages/react-native-nitro-sqlite/cpp/NitroSQLiteStatementTail.hpp",
"packages/react-native-nitro-sqlite/cpp/SQLiteDatabaseMigration.*",
"packages/react-native-nitro-sqlite/cpp/SQLiteDatabaseConnections.*",
"packages/react-native-nitro-sqlite/cpp/SQLiteExecuteBatch.*",
"packages/react-native-nitro-sqlite/cpp/SQLiteOperations.*",
"packages/react-native-nitro-sqlite/cpp/SQLiteStatementGroup.hpp",
"packages/react-native-nitro-sqlite/cpp/SQLiteStatementTail.hpp",
"packages/react-native-nitro-sqlite/cpp/sqlite/sqlite3.*",
"packages/react-native-nitro-sqlite/cpp/sqlite/sqlite3-symbol-prefix.h",
"packages/react-native-nitro-sqlite-vec/cpp/**",
Expand Down
4 changes: 2 additions & 2 deletions docs/content/docs/guides/attach-databases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ db.close()

## File paths and aliases

The example assumes the tables and files already exist. SQLite can create the attached file when it is missing, so verify the intended path when opening prepopulated data. `attach()` and `detach()` are synchronous connection operations; they fail while the connection queue is busy. A failed attach or detach throws `NitroSQLiteError` through the connection wrapper.
The example assumes the tables and files already exist. SQLite can create the attached file when it is missing, so verify the intended path when opening prepopulated data. `attach()` and `detach()` are synchronous connection operations; they fail while the connection queue is busy. A failed attach or detach throws `SQLiteError` through the connection wrapper.

Only pass database names, locations, and aliases you control. The library does not bind these as parameters. Query values still belong in `?` parameters. See [database lifecycle](/docs/guides/database-lifecycle) for the location convention and the generated [`NitroSQLiteConnection` reference](/api/react-native-nitro-sqlite/interfaces/NitroSQLiteConnection) for signatures.
Only pass database names, locations, and aliases you control. The library does not bind these as parameters. Query values still belong in `?` parameters. See [database lifecycle](/docs/guides/database-lifecycle) for the location convention and the generated [`Connection` reference](/api/react-native-nitro-sqlite/interfaces/Connection) for signatures.
2 changes: 1 addition & 1 deletion docs/content/docs/guides/database-lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Only pass database names and locations you control. The library does not validat

To open a prepopulated database, copy the SQLite file into the intended app directory before calling `open()`. Use the same `name` and `location` when you open it. A missing file creates a new, empty database, so verify the copy if your schema must already exist. See [file lifetimes](/docs/concepts/databases-and-connections#file-lifetimes) for WAL companion files.

The platform pages describe the database roots and storage settings for [iOS](/docs/configuration/ios#database-location), [Android](/docs/configuration/android#database-location), and [macOS](/docs/configuration/macos). The generated [`NitroSQLiteConnection` reference](/api/react-native-nitro-sqlite/interfaces/NitroSQLiteConnection) lists the lifecycle methods.
The platform pages describe the database roots and storage settings for [iOS](/docs/configuration/ios#database-location), [Android](/docs/configuration/android#database-location), and [macOS](/docs/configuration/macos). The generated [`Connection` reference](/api/react-native-nitro-sqlite/interfaces/Connection) lists the lifecycle methods.

## Runtime teardown

Expand Down
6 changes: 3 additions & 3 deletions docs/content/docs/guides/encryption.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ export function openPrivateDatabase(encryptionKey: string) {

Use a new database name when adding encryption to an app. Passing a key to an existing plaintext database fails; it does not encrypt that file. To migrate, open the old file without a key, create a separate keyed database, copy the data, and verify the new file before removing the old one. See [database lifecycle](/docs/guides/database-lifecycle) for file and connection cleanup.

The [`open()` reference](/api/react-native-nitro-sqlite/functions/open) documents the managed call, and [`NitroSQLiteConnectionOptions`](/api/react-native-nitro-sqlite/interfaces/NitroSQLiteConnectionOptions) lists its options. Raw native callers can pass the key as the fourth argument to [`NitroSQLiteNative.open()`](/api/react-native-nitro-sqlite/hybrid-objects/NitroSQLiteNative) or `openConnection()`, after `readOnly`. The [TypeORM integration](/docs/integrations/typeorm#encrypt-a-typeorm-database) passes the key through `extra`.
The [`open()` reference](/api/react-native-nitro-sqlite/functions/open) documents the managed call, and [`ConnectionOptions`](/api/react-native-nitro-sqlite/interfaces/ConnectionOptions) lists its options. Raw native callers can pass the key as the fourth argument to [`NativeSQLite.open()`](/api/react-native-nitro-sqlite/hybrid-objects/NativeSQLite) or `openConnection()`, after `readOnly`. The [TypeORM integration](/docs/integrations/typeorm#encrypt-a-typeorm-database) passes the key through `extra`.

## Handle open failures

Managed `open()` throws `NitroSQLiteError`. Check its `type` when you need to tell a missing SEE build from a bad key:
Managed `open()` throws `SQLiteError`. Check its `type` when you need to tell a missing SEE build from a bad key:

| `error.type` | Cause | What to do |
| --------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| `EncryptionNotEnabled` | You supplied a key, but the native build does not include SEE. | Check the source replacement and compile flag, then rebuild the app. |
| `DatabaseCannotBeDecrypted` | The key is empty or contains a NUL byte, the file is plaintext, or SEE cannot read it with that key. | Check the key and file. Migrate a plaintext database before opening it with a key. |

A keyed open checks the database header and reads its schema before returning, so these failures surface during `open()`. Omitting the key keeps the usual unencrypted open path; an encrypted file then fails when SQLite first tries to read it. Calls through `NitroSQLite.native` throw raw native errors rather than `NitroSQLiteError`.
A keyed open checks the database header and reads its schema before returning, so these failures surface during `open()`. Omitting the key keeps the usual unencrypted open path; an encrypted file then fails when SQLite first tries to read it. Calls through `NitroSQLite.native` throw raw native errors rather than `SQLiteError`.

SEE does not encrypt TEMP tables or in-memory databases. Keep sensitive data in the keyed database file rather than those locations. A keyed open adds a header read and schema query; query and write costs depend on the SEE algorithm you choose. Measure those costs on your target devices. See [SQLite's SEE documentation](https://www.sqlite.org/see/doc/trunk/www/readme.wiki) for its encryption variants and limits.
2 changes: 1 addition & 1 deletion docs/content/docs/guides/load-sql-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ The loader counts executed lines in `commands` and adds their affected row count

SQLite can reject a statement or fail to commit the import. NitroSQLite attempts one rollback after a failed import transaction, preserving the source path and the original SQL error. Statement failures also include the one-based file line and failing command. A failed BEGIN does not trigger rollback of an existing transaction. If rollback itself fails, its error is appended to the original import error.

The managed methods throw or reject with `NitroSQLiteError` and native category `CouldNotLoadFile`. After a successful rollback, completed statements from the file are discarded and the connection can be used again. The error includes the failing SQL text, so avoid including sensitive literal values in files whose errors may be logged.
The managed methods throw or reject with `SQLiteError` and native category `CouldNotLoadFile`. After a successful rollback, completed statements from the file are discarded and the connection can be used again. The error includes the failing SQL text, so avoid including sensitive literal values in files whose errors may be logged.

Both methods return a [`FileLoadResult`](/api/react-native-nitro-sqlite/interfaces/FileLoadResult) with optional `commands` and `rowsAffected` numbers.
1 change: 1 addition & 0 deletions docs/content/docs/guides/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"attach-databases",
"load-sql-file",
"performance",
"migrate-to-nitro-v1",
"migrate-from-quick-sqlite",
"ai-agents"
]
Expand Down
51 changes: 51 additions & 0 deletions docs/content/docs/guides/migrate-to-nitro-v1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: Migrate to Nitro V1
description: Update type imports for the Nitro V1 migration.
---

A SQLite connection owns a database handle. A prepared statement belongs to that connection, and a query result contains the rows and metadata returned by a statement. Nitro SQLite uses shorter names for these types with Nitro V1.

Update your type imports using the table below. The old names remain available as deprecated aliases.

| Previous name | Replacement |
| -------------------------------- | ------------------------- |
| `NitroSQLiteConnection` | `Connection` |
| `NitroSQLiteConnectionOptions` | `ConnectionOptions` |
| `NitroSQLiteQueryResultRows` | `QueryResultRows` |
| `NitroSQLiteQueryColumnMetadata` | `QueryColumnMetadata` |
| `NitroSQLiteQueryResult` | `NativeQueryResult` |
| `NitroSQLiteQueryRows` | `NativeQueryRows` |
| `NitroSQLitePreparedStatement` | `NativePreparedStatement` |
| `NitroSQLiteNative` | `NativeSQLite` |
| `NitroSQLiteError` | `SQLiteError` |
| `NitroSQLiteExceptionType` | `SQLiteExceptionType` |
| `TypeOrmNitroSQLiteConnection` | `TypeOrmConnection` |

`NativeQueryResult`, `NativePreparedStatement`, and `NativeSQLite` describe values exposed through `NitroSQLite.native`. The managed API keeps its `QueryResult` and `PreparedStatement` names.

```ts
import { open, SQLiteError } from 'react-native-nitro-sqlite'
import type { ConnectionOptions } from 'react-native-nitro-sqlite'

const options: ConnectionOptions = { name: 'app.sqlite' }
const db = open(options)

try {
const { results } = db.execute('SELECT sqlite_version() AS version')
console.log(results[0]?.version)
} catch (error) {
if (error instanceof SQLiteError) {
console.error(error.type, error.message)
} else {
throw error
}
} finally {
db.close()
}
```

`SQLiteError` and `NitroSQLiteError` refer to the same constructor, and both exception-category exports refer to the same object. The error's `name` remains `NitroSQLiteError`.

If your native code includes helper headers, replace their `NitroSQLite` filename prefix with `SQLite`, for example `NitroSQLiteOperations.hpp` becomes `SQLiteOperations.hpp`. The package name, `NitroSQLite` entry point, and native module names stay the same.

See [Getting Started](/docs) for Nitro V1's platform requirements and Swift Package Manager setup.
Loading
Loading