Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expo-sqlite/kv-store persist plugin #444

Merged
merged 2 commits into from
Jan 23, 2025
Merged

Conversation

catalinmiron
Copy link
Contributor

@catalinmiron catalinmiron commented Jan 21, 2025

Add expo-sqlite/kv-store to the persist plugins list.

More about the expo-sqlite/kv-store

Initial PR: #413

Usage:

  • default database
import { Storage } from 'expo-sqlite/kv-store';

export const persistOptions = configureSynced({
  persist: {
    plugin: observablePersistSqlite(Storage),
  },
});
  • custom database file
import { SQLiteStorage } from 'expo-sqlite/kv-store';

export const persistOptions = configureSynced({
  persist: {
    plugin: observablePersistSqlite(new SQLiteStorage("myOtherSQLiteDatabase")),
  },
});

@byCedric
Copy link

byCedric commented Jan 21, 2025

This might require either one of these things too:

  1. Add an optional peer dependency constraint to expo-sqlite: >=15.0.0.
  2. Remove the default Storage value, and make it explicit.

If you want to access expo-sqlite within a library, there has to be some sort of dependency reference towards it. Otherwise, isolated modules would break it by not symlinking the modules together. But, you can also work around it by letting users pass the reference on both cases, because expo-sqlite should be installed by the user when the user uses it.

E.g.

import { Storage } from 'expo-sqlite/kv-store';

export const persistOptions = configureSynced({
  persist: {
    plugin: observablePersistSqlite(Storage),
  },
});

@catalinmiron
Copy link
Contributor Author

@byCedric you are right, as the docs mentioned for AsyncStorage, there's an initial step to install the dependency but it is not saying anything about the versioning (which we should enforce)

  1. I agree, since kv-store it's available from >=15.x
  2. Great point, I will make the Storage explicit and make it required. @jmeistrich maybe when we add the docs, we should add the option with the custom database name as well, because Storage = new SQLiteStorage('ExpoSQLiteStorage')

I am going to fix this tomorrow. Thanks @byCedric for the suggestions, really valid points 👍

@catalinmiron
Copy link
Contributor Author

@jmeistrich ready for review

@jmeistrich jmeistrich merged commit cece5e1 into LegendApp:main Jan 23, 2025
3 checks passed
@jmeistrich
Copy link
Contributor

Thank you @catalinmiron! And thanks @byCedric for the help ❤️

Merged and released in beta.24

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.

3 participants