Skip to content

Conversation

DominicGBauer
Copy link
Contributor

@DominicGBauer DominicGBauer commented Jan 16, 2025

Description

Allow additional sqlite extensions to be loaded by users as requested here #452 (comment).

This includes and extensions option in sqliteOptions which would look something like this to the user

    let libPath: string
    if (Platform.OS === 'ios') {
      const bundlePath: string = NativeModules.PowerSyncOpSqlite.getBundlePath();
      libPath = getDylibPath('co.powersync.sqlite', 'powersync-sqlite-core')
    } else {
      libPath = 'libpowersync';
    }

    const factory = new OPSqliteOpenFactory({
      dbFilename: 'sqlite.db',
      sqliteOptions: {
        extensions: [
            { path: libPath, entryPoint: 'sqlite3_powersync_init' }
        ]
      }
    });

It also removes the use of getBundlePath in favor of getDylibPath

We can't remove the entire Turbo Module because it includes the powersync-sqlite-core module for users without them needing to manually include it.

Testing

I excluded the powersync extension from being loaded in the powersync-op-sqlite library and used the above to include it from the client side in the react native supabase todolist demo. The powersync extension was loaded correctly. I also tested the case where a user does not include any extensions.

I also ran a dev release and installed into an isolated react-native-supabase-todolist demo for both iOS and Android and it worked.

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 3fd07ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/op-sqlite Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Chriztiaan
Chriztiaan previously approved these changes Jan 16, 2025
@stevensJourney
Copy link
Collaborator

We should probably add some notes to the readme or docs about this feature.

For the example in the PR description, we could use an API from OP-SQLite for the iOS extension path:
See getDylibPath. We implemented something simillar in our OP-SQLite package, but we should update our package to use the OP SQLite API instead - this would make our adapter package much simpler.

@DominicGBauer
Copy link
Contributor Author

@stevensJourney great points. I've implemented getDylibPath and updated the README of op-sqlite package.

@DominicGBauer
Copy link
Contributor Author

@rkistner and @stevensJourney I needed to revert the change of using getDylibPath. I tested it incorrectly last week and after doing a final run through ran into an issue where it can't find the lib path using getDylibPath. It requires the bundleId but there is no bundleId in the powersync-sqlite-core info.plist so it is never found using getDylibPath. I'm not sure if this is why Mugi opted to do it this way originally.

@DominicGBauer DominicGBauer force-pushed the feat/add-load-extensions-to-opsqlite-2 branch from aa1fb53 to 4d42566 Compare January 21, 2025 12:20
@DominicGBauer
Copy link
Contributor Author

@stevensJourney, @Chriztiaan and @rkistner this PR has been updated. Please can you re-review when you get a chance.

@DominicGBauer DominicGBauer merged commit 3a37054 into main Jan 21, 2025
6 checks passed
@DominicGBauer DominicGBauer deleted the feat/add-load-extensions-to-opsqlite-2 branch January 21, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants