Skip to content

Commit 7d18fa6

Browse files
committed
dyload
1 parent e879c93 commit 7d18fa6

File tree

5 files changed

+20593
-26161
lines changed

5 files changed

+20593
-26161
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { getDylibPath, type DB } from '@op-engineering/op-sqlite';
2+
import { OPSQLiteDBAdapter } from '@powersync/op-sqlite';
3+
import * as FileSystem from 'expo-file-system';
4+
5+
export class ExpoAdapter extends OPSQLiteDBAdapter {
6+
public async loadPowerSyncExtension(DB: DB) {
7+
console.log('OVERRIDDEN LOAD');
8+
// if (Platform.OS === 'ios') {
9+
const libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
10+
console.log('Bundled path', libPath);
11+
// DB.loadExtension(libPath, 'sqlite3_powersync_init');
12+
// }
13+
14+
//android arch64
15+
// const fileUrl =
16+
// 'https://www.dropbox.com/scl/fi/sst93bsf1ritnqoe3oe9w/libpowersync.so?rlkey=c34n51pb6y5065su6o0ixczc4&st=u76jpyp2&dl=1';
17+
// x64
18+
// const fileUrl =
19+
// 'https://www.dropbox.com/scl/fi/13ho6v2w6fau3eq8wujv3/libpowersync_x64-1.so?rlkey=02r25q59nax4hhzppuvregv9d&st=mfbwtz0q&dl=1';
20+
// ios slice
21+
// 'https://www.dropbox.com/scl/fi/d4v2xanai0q8yi4jb17b7/powersync-sqlite-core?rlkey=r0dy109laxuxgkcilbcwpc7t9&st=3sya938g&dl=1';
22+
// const fileName = 'libpowersync.so'; // no .dylib
23+
// bundled ios xcf
24+
const fileUrl =
25+
'https://www.dropbox.com/scl/fi/d4v2xanai0q8yi4jb17b7/powersync-sqlite-core?rlkey=r0dy109laxuxgkcilbcwpc7t9&st=xn3hfqx7&dl=1';
26+
27+
const fileName = 'powersync-sqlite-core';
28+
// const uri = await this.downloadAndSaveFile(fileUrl, fileName);
29+
// const uri =
30+
// 'file:///Users/christiaanlandman/Library/Developer/CoreSimulator/Devices/2F1E3D3B-1A15-4D8C-9807-F9BB5DDF9B2C/data/Containers/Data/Application/809665CE-0CC3-465A-B6E7-F56B4FC5BE8E/Documents/powersync-sqlite-core';
31+
// const path = uri?.replace('file://', '');
32+
33+
// const path =
34+
// '/Users/christiaanlandman/Library/Developer/CoreSimulator/Devices/2F1E3D3B-1A15-4D8C-9807-F9BB5DDF9B2C/data/Containers/Data/Application/3FCF064A-2A10-40C1-B4FF-93202B873163/Documents/powersync-sqlite-core';
35+
// console.log('Loading extension', path);
36+
37+
try {
38+
DB.loadExtension(
39+
'/Users/christiaanlandman/Library/Developer/CoreSimulator/Devices/2F1E3D3B-1A15-4D8C-9807-F9BB5DDF9B2C/data/Containers/Data/Application/809665CE-0CC3-465A-B6E7-F56B4FC5BE8E/Documents/powersync-sqlite-core',
40+
'sqlite3_powersync_init'
41+
);
42+
console.log('success');
43+
} catch (error) {
44+
console.error('Loading error:', error);
45+
}
46+
}
47+
48+
private async downloadAndSaveFile(url: any, fileName: any) {
49+
try {
50+
console.log('Starting simple download...');
51+
52+
const downloadDest = `${FileSystem.documentDirectory}${fileName}`;
53+
54+
const { uri } = await FileSystem.downloadAsync(url, downloadDest);
55+
56+
console.log('File downloaded to:', uri);
57+
await new Promise((resolve) => setTimeout(resolve, 2000));
58+
return uri;
59+
} catch (error) {
60+
console.error('Simple download error:', error);
61+
}
62+
return '';
63+
}
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/common';
2+
3+
import { OPSqliteOpenFactory, OPSQLiteOpenFactoryOptions } from '@powersync/op-sqlite';
4+
import { ExpoAdapter } from './adapter';
5+
6+
export class ExpoFactory extends OPSqliteOpenFactory {
7+
constructor(protected options: OPSQLiteOpenFactoryOptions) {
8+
super(options);
9+
// this.sqliteOptions = {
10+
// ...DEFAULT_SQLITE_OPTIONS,
11+
// ...this.options.sqliteOptions
12+
// };
13+
}
14+
15+
openDB(): DBAdapter {
16+
return new ExpoAdapter({
17+
name: this.options.dbFilename,
18+
dbLocation: this.options.dbLocation,
19+
sqliteOptions: this.sqliteOptions
20+
});
21+
}
22+
}

demos/react-native-supabase-todolist/library/powersync/system.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SupabaseConnector } from '../supabase/SupabaseConnector';
1212
import { AppSchema } from './AppSchema';
1313
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
1414
import { OPSqliteOpenFactory } from '@powersync/op-sqlite';
15+
import { ExpoFactory } from './factory';
1516

1617
const logger = createBaseLogger();
1718
logger.useDefaults();
@@ -29,9 +30,10 @@ export class System {
2930
this.supabaseConnector = new SupabaseConnector(this);
3031
this.storage = this.supabaseConnector.storage;
3132

32-
const factory = new OPSqliteOpenFactory({
33+
const factory = new ExpoFactory({
3334
dbFilename: 'sqlite.db'
3435
});
36+
3537
this.powersync = new PowerSyncDatabase({ database: factory, schema: AppSchema });
3638
/**
3739
* The snippet below uses OP-SQLite as the default database adapter.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface OPSQLiteOpenFactoryOptions extends SQLOpenOptions {
66
sqliteOptions?: SqliteOptions;
77
}
88
export class OPSqliteOpenFactory implements SQLOpenFactory {
9-
private sqliteOptions: Required<SqliteOptions>;
9+
protected sqliteOptions: Required<SqliteOptions>;
1010

1111
constructor(protected options: OPSQLiteOpenFactoryOptions) {
1212
this.sqliteOptions = {

0 commit comments

Comments
 (0)