Skip to content

Commit d287780

Browse files
committed
Copy relevant sections from old op-sqlite readme (#1014)
1 parent 299adaf commit d287780

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

packages/react-native/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,82 @@ See a summary of features [here](https://docs.powersync.co/client-sdk-references
1818
npx expo install @powersync/react-native @op-engineering/op-sqlite
1919
```
2020

21+
## Configuration options
22+
23+
### Encryption with SQLCipher
24+
25+
To enable SQLCipher you need to add the following configuration option to your application's `package.json`. Note that for [monorepos](https://op-engineering.github.io/op-sqlite/docs/installation) you may have to add this configuration to the monorepo root `package.json` instead, this depends on where your package manager tool hoists modules.
26+
27+
```json
28+
{
29+
// your normal package.json
30+
// ...
31+
"op-sqlite": {
32+
"sqlcipher": true
33+
}
34+
}
35+
```
36+
37+
Additionally you will need to add an [encryption key](https://www.zetetic.net/sqlcipher/sqlcipher-api/#key) to the OPSQLite factory constructor
38+
39+
```typescript
40+
const db = new PowerSyncDatabase({
41+
schema: new Schema(...),
42+
database: {
43+
dbFilename: 'sqlite.db',
44+
sqliteOptions: {
45+
encryptionKey: 'your-encryption-key'
46+
}
47+
}
48+
});
49+
```
50+
51+
### Full-Text Search
52+
53+
To enable the `fts5` extension, configure OP-SQLite in your (or for monorepos, the root) `package.json`:
54+
55+
```json
56+
{
57+
// your normal package.json
58+
// ...
59+
"op-sqlite": {
60+
"fts5": true
61+
}
62+
}
63+
```
64+
65+
### Loading SQLite extensions
66+
67+
To load additional SQLite extensions include the `extensions` option in `sqliteOptions` which expects an array of objects with a `path` and an `entryPoint`:
68+
69+
```js
70+
sqliteOptions: {
71+
extensions: [{ path: libPath, entryPoint: 'sqlite3_powersync_init' }];
72+
}
73+
```
74+
75+
More info can be found in the [OP-SQLite docs](https://op-engineering.github.io/op-sqlite/docs/api/#loading-extensions).
76+
77+
Example usage:
78+
79+
```ts
80+
import { getDylibPath } from '@op-engineering/op-sqlite';
81+
82+
let libPath: string;
83+
if (Platform.OS === 'ios') {
84+
libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
85+
} else {
86+
libPath = 'libpowersync';
87+
}
88+
89+
const factory = new OPSqliteOpenFactory({
90+
dbFilename: 'sqlite.db',
91+
sqliteOptions: {
92+
extensions: [{ path: libPath, entryPoint: 'sqlite3_powersync_init' }]
93+
}
94+
});
95+
```
96+
2197
## Install Polyfills
2298

2399
- Polyfills are required for [watched queries](#babel-plugins-watched-queries) using the Async Iterator response format.

packages/react-native/src/db/PowerSyncDatabase.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
DBAdapter,
66
PowerSyncBackendConnector,
77
PowerSyncDatabaseConstructor,
8-
PowerSyncDatabaseOptions,
98
SyncStreamConnectionMethod
109
} from '@powersync/common';
1110
import {
@@ -86,6 +85,6 @@ class ReactNativePowerSyncDatabase extends BasePowerSyncDatabase<ReactNativeData
8685
* });
8786
* ```
8887
*/
89-
export const PowerSyncDatabase: PowerSyncDatabaseConstructor<PowerSyncDatabaseOptions> = ReactNativePowerSyncDatabase;
88+
export const PowerSyncDatabase: PowerSyncDatabaseConstructor<ReactNativeDatabaseOptions> = ReactNativePowerSyncDatabase;
9089

9190
export interface PowerSyncDatabase extends CommonPowerSyncDatabase {}

0 commit comments

Comments
 (0)