Skip to content
Merged
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
61 changes: 20 additions & 41 deletions bun.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/content/docs/integrations/typeorm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Nitro SQLite exports `typeORMDriver` for TypeORM's `react-native` database type.

## Configure module resolution

Install `typeorm`, `react-native-nitro-sqlite`, and `babel-plugin-module-resolver` in the app. The repository's working example uses TypeORM 0.3.27 and makes two resolution changes:
Install `typeorm`, `react-native-nitro-sqlite`, `babel-plugin-module-resolver`, and `@babel/plugin-transform-class-static-block` in the app. The repository's working example uses TypeORM 1.1.1. Its browser build uses static class blocks, so the Babel transform is needed in addition to two resolution changes:

1. Expose `./package.json` in TypeORM's `exports` map. The repository keeps this as a persistent package patch:

Expand All @@ -25,6 +25,7 @@ Install `typeorm`, `react-native-nitro-sqlite`, and `babel-plugin-module-resolve
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
'@babel/plugin-transform-class-static-block',
[
'module-resolver',
{
Expand Down Expand Up @@ -95,15 +96,15 @@ The failure callbacks for `openDatabase` and `executeSql` are typed to receive a

## Encrypt a TypeORM database

After building Nitro SQLite with licensed SEE, pass the key through the DataSource's `extra` option. TypeORM forwards `extra` to `typeORMDriver.openDatabase`:
After building Nitro SQLite with licensed SEE, pass the key through the DataSource's `encryptionKey` option. TypeORM 1.1.1 forwards it to `typeORMDriver.openDatabase`:

```ts
const dataSource = new DataSource({
type: 'react-native',
database: 'private.sqlite',
location: '.',
driver: typeORMDriver,
extra: { encryptionKey },
encryptionKey,
entities: [NoteEntity],
})
```
Expand Down
1 change: 1 addition & 0 deletions example/babel.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function createExampleBabelConfig(projectRoot, { buffer, crypto } = {}) {
return {
presets: ['module:@react-native/babel-preset'],
plugins: [
'@babel/plugin-transform-class-static-block',
[
'module-resolver',
{
Expand Down
5 changes: 3 additions & 2 deletions example/macos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"react-native-nitro-modules": "0.37.1",
"react-native-nitro-sqlite": "workspace:*",
"react-native-nitro-sqlite-vec": "workspace:*",
"reflect-metadata": "^0.1.13",
"typeorm": "0.3.27",
"reflect-metadata": "^0.2.2",
"typeorm": "1.1.1",
"util": "^0.12.5"
},
"devDependencies": {
"@babel/plugin-transform-class-static-block": "^7.28.3",
"@react-native-community/cli": "19.1.2",
"@react-native-community/cli-platform-android": "19.1.2",
"@react-native-community/cli-platform-apple": "19.1.2",
Expand Down
5 changes: 3 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
"react-native-quick-crypto": "^1.1.5",
"react-native-safe-area-context": "^5.10.0",
"react-native-screens": "^4.28.0",
"reflect-metadata": "^0.1.13",
"reflect-metadata": "^0.2.2",
"stream-browserify": "^3.0.0",
"typeorm": "0.3.27",
"typeorm": "1.1.1",
"util": "^0.12.5"
},
"devDependencies": {
"@babel/core": "^7.28.5",
"@babel/plugin-transform-class-static-block": "^7.28.3",
"@babel/plugin-proposal-decorators": "^7.20.5",
"@babel/preset-env": "^7.25.4",
"@babel/runtime": "^7.25.4",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"nitrogen": "0.37.1",
"prettier": "^3.6.2",
"release-it": "^19.2.4",
"typeorm": "0.3.27",
"typeorm": "1.1.1",
"typescript": "^6.0.3",
"typescript-eslint": "^8.46.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-nitro-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"typeorm": "0.3.27"
"typeorm": "1.1.1"
},
"devDependencies": {
"@react-native/jest-preset": "0.87.1",
Expand Down
21 changes: 21 additions & 0 deletions packages/react-native-nitro-sqlite/src/__tests__/typeORM.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jest.mock('../nitro')

import { DataSource } from 'typeorm'
import { HybridNitroSQLite } from '../nitro'
import { closeDatabaseQueue, isDatabaseOpen } from '../DatabaseQueue'
import { typeORMDriver } from '../typeORM'
Expand All @@ -20,6 +21,26 @@ afterEach(() => {
})

describe('typeORMDriver', () => {
it('forwards a top-level encryption key from TypeORM', async () => {
const dataSource = new DataSource({
type: 'react-native',
database: dbName,
location: '.',
driver: typeORMDriver,
encryptionKey: 'secret',
entities: [],
})

await dataSource.initialize()
expect(HybridNitroSQLite.open).toHaveBeenCalledWith(
dbName,
'.',
undefined,
'secret',
)
await dataSource.destroy()
})

it('passes an encryption key through the TypeORM adapter', () => {
const connection = typeORMDriver.openDatabase(
{ name: dbName, encryptionKey: 'secret' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
diff --git a/node_modules/typeorm/package.json b/node_modules/typeorm/package.json
index cb64ad7..17e4941 100644
--- a/node_modules/typeorm/package.json
+++ b/node_modules/typeorm/package.json
@@ -17,6 +17,7 @@
"email": "pleerock.me@gmail.com"
"email": "maintainers@typeorm.io"
},
"exports": {
+ "./package.json": "./package.json",
Expand Down
Loading