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 Packages (expo-sqlite & op-sqlite) #3841

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

austinm911
Copy link

@austinm911 austinm911 commented Feb 20, 2025

See https://discord.com/channels/830183651022471199/1329821985999552582

Went ahead and migrated much of the integration done in React Native Replicache into the rocicorp monorepo.

I wasn't really sure to publish this code to test in a standalone react native/expo app and might not have much time to work on that. So figured I would throw this PR up for now. I'll leave that up to y'all how you might want to handle.

Copy link

vercel bot commented Feb 20, 2025

@austinm911 is attempting to deploy a commit to the Rocicorp Team on Vercel.

A member of the Team first needs to authorize it.


export interface SQLResultSetRowList {
length: number;
item(index: number): {value: string}; // TODO: confirm this is correct, this was typed as `any` in the original code
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone confirm this is the correct type? I can cast back to any if preferred

@austinm911 austinm911 changed the title Add Expo Packages Add Expo Packages (expo-sqlite & op-sqlite) Feb 20, 2025
@aboodman
Copy link
Contributor

Austin, is this ready for another look?

@austinm911
Copy link
Author

@aboodman a few misc. comments i'll need to likely clean up but it's good for you to review.

Copy link
Contributor

@arv arv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice.

I like where this is going. I tried to be as detailed as possible so do not be deterred by the number of comments.

If you are low on time I'd be more than willing to take over this work that you started.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this needed for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orphaned file from colocating the react-native-replicache package as a submodule during dev, should be deleted

item(index: number): {value: string}; // TODO: confirm this is correct, this was typed as `any` in the original code
}

export abstract class SQLiteTransaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is all abstract maybe use an interface?

Comment on lines +21 to +25
export interface SQLDatabase {
transaction: () => SQLiteTransaction;
destroy: () => Promise<void>;
close: () => Promise<void>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export interface SQLDatabase {
transaction: () => SQLiteTransaction;
destroy: () => Promise<void>;
close: () => Promise<void>;
}
export interface SQLDatabase {
transaction(): SQLiteTransaction;
destroy(): Promise<void>;
close(): Promise<void>;
}

}

export interface GenericSQLiteDatabaseManager {
open: (name: string) => Promise<SQLDatabase>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
open: (name: string) => Promise<SQLDatabase>;
open(name: string): Promise<SQLDatabase>;

* transaction support. Read transactions use SQLite's READ mode while write
* transactions use the default mode.
*/
export class ReplicacheGenericStore implements KVStore {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about SQLiteStore or GenericSQLiteStore.

const genericDatabase: GenericSQLiteDatabaseManager = {
open: (name: string) => {
const db = OPSQLite.open({name});
return Promise.resolve({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to use a MaybePromise type so that these extra microtasks can be skipped.

Not a big deal but worth thinking about/benchmarking sometime.

}>();
#txEnded = false;

// eslint-disable-next-line @typescript-eslint/parameter-properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

await new Promise<void>((resolve, reject) => {
let didResolve = false;
try {
void this._db.transaction(async tx => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same consideration here.

Maybe the test will tell.

args?: (string | number | null)[] | undefined,
): Promise<SQLResultSetRowList> {
const tx = this.#assertTransactionReady();
const {rows} = await tx.execute(sqlStatement, args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use a prepare (cache) for this one too?

https://op-engineering.github.io/op-sqlite/docs/api#prepared-statements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const tx = this.#assertTransactionReady();
const {rows} = await tx.execute(sqlStatement, args);

return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These extra object will cost. Let's simplify the interface to a plain array since we already have one.

@arv
Copy link
Contributor

arv commented Feb 25, 2025

@Braden1996 FYI

@austinm911
Copy link
Author

austinm911 commented Feb 25, 2025

This is very nice.

I like where this is going. I tried to be as detailed as possible so do not be deterred by the number of comments.

If you are low on time I'd be more than willing to take over this work that you started.

I'm pretty jammed this week so I won't be able to take a look in great detail until this weekend, so whatever you'd like. I'm good with you taking over.

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