-
Notifications
You must be signed in to change notification settings - Fork 93
Add Expo Packages (expo-sqlite & op-sqlite) #3841
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
Conversation
This reverts commit bad185c.
@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 |
There was a problem hiding this comment.
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
Austin, is this ready for another look? |
@aboodman a few misc. comments i'll need to likely clean up but it's good for you to review. |
There was a problem hiding this 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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, use executeRaw
?
https://op-engineering.github.io/op-sqlite/docs/api#raw-execution
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
@Braden1996 FYI |
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. |
Thanks for the update @austinm911 |
@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? |
Thanks for the contribution @austinm911 - moved this here! #4669 |
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.
hello-zero-expo
standalone package