Skip to content

Commit 4d8f23a

Browse files
committed
chore: implement getDylibPath and update docs
1 parent f0c7cf2 commit 4d8f23a

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

packages/powersync-op-sqlite/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,40 @@ const factory = new OPSqliteOpenFactory({
6868
});
6969
```
7070

71+
### Loading SQLite extensions
72+
73+
To load additional SQLite extensions include the `extensions` option in `sqliteOptions` which expects an array of objects with a `path` and an `entryPoint`:
74+
75+
```js
76+
sqliteOptions: {
77+
extensions: [
78+
{ path: libPath, entryPoint: 'sqlite3_powersync_init' }
79+
]
80+
}
81+
```
82+
83+
More info can be found in the [OP-SQLite docs](https://op-engineering.github.io/op-sqlite/docs/api/#loading-extensions).
84+
85+
Example usage:
86+
87+
```ts
88+
let libPath: string
89+
if (Platform.OS === 'ios') {
90+
libPath = getDylibPath('powersync-sqlite-core', 'powersync-sqlite-core')
91+
} else {
92+
libPath = 'libpowersync';
93+
}
94+
95+
const factory = new OPSqliteOpenFactory({
96+
dbFilename: 'sqlite.db',
97+
sqliteOptions: {
98+
extensions: [
99+
{ path: libPath, entryPoint: 'sqlite3_powersync_init' }
100+
]
101+
}
102+
});
103+
```
104+
71105
## Native Projects
72106

73107
This package uses native libraries. Create native Android and iOS projects (if not created already) by running:

packages/powersync-op-sqlite/src/db/OPSqliteAdapter.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
2-
import { ANDROID_DATABASE_PATH, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
1+
import {
2+
BaseObserver,
3+
DBAdapter,
4+
DBAdapterListener,
5+
DBLockOptions,
6+
QueryResult,
7+
Transaction
8+
} from '@powersync/common';
9+
import {
10+
ANDROID_DATABASE_PATH,
11+
getDylibPath,
12+
IOS_LIBRARY_PATH,
13+
open,
14+
type DB
15+
} from '@op-engineering/op-sqlite';
316
import Lock from 'async-lock';
417
import { OPSQLiteConnection } from './OPSQLiteConnection';
5-
import { NativeModules, Platform } from 'react-native';
18+
import { Platform } from 'react-native';
619
import { SqliteOptions } from './SqliteOptions';
720

821
/**
@@ -135,8 +148,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
135148

136149
private loadPowerSyncExtension(DB: DB) {
137150
if (Platform.OS === 'ios') {
138-
const bundlePath: string = NativeModules.PowerSyncOpSqlite.getBundlePath();
139-
const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
151+
const libPath = getDylibPath('powersync-sqlite-core', 'powersync-sqlite-core')
140152
DB.loadExtension(libPath, 'sqlite3_powersync_init');
141153
} else {
142154
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');

0 commit comments

Comments
 (0)