|
| 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 | +} |
0 commit comments