Skip to content

Conversation

austinm911
Copy link
Contributor

@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
Contributor 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
Contributor 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.

.gitmodules Outdated
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
Contributor 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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave in for now

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.

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

Docs seem to discourage that:

Using prepared statements for writes inside a transaction is discouraged, you gain very little performance when writting to the database and they are not part of the internal lock mechanism of op-sqlite.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

holding off on the prepared statement per the comments above. @arv maybe executeRaw could be refactored into this later?

@arv
Copy link
Contributor

arv commented Feb 25, 2025

@Braden1996 FYI

@austinm911
Copy link
Contributor 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.

@austinm911 austinm911 marked this pull request as draft April 3, 2025 00:13
@arv
Copy link
Contributor

arv commented Apr 3, 2025

Thanks for the update @austinm911

@austinm911
Copy link
Contributor Author

@arv For the remainder of the comments that deal more with internals of how sqlite work under the hood (like withExclusiveTransactionAsync), I think it's better that someone with a better understanding takes over. I made an attempt with the expo-sqlite test (with AI to help) that i'll leave here, but seems like expo-sqlite has to mocked. I don't know if my test attempt is going in the right direction.

So perhaps someone else could take it over from here?

@0xcadams
Copy link
Collaborator

Thanks for the contribution @austinm911 - moved this here! #4669

@0xcadams 0xcadams closed this Jul 25, 2025
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.

5 participants