-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
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.
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
item(index: number): {value: string}; // TODO: confirm this is correct, this was typed as `any` in the original code | ||
} | ||
|
||
export abstract class SQLiteTransaction { |
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.
If it is all abstract maybe use an interface?
export interface SQLDatabase { | ||
transaction: () => SQLiteTransaction; | ||
destroy: () => Promise<void>; | ||
close: () => Promise<void>; | ||
} |
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.
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>; |
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.
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 { |
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.
How about SQLiteStore
or GenericSQLiteStore
.
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.
}>(); | ||
#txEnded = false; | ||
|
||
// eslint-disable-next-line @typescript-eslint/parameter-properties |
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.
fix
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
const tx = this.#assertTransactionReady(); | ||
const {rows} = await tx.execute(sqlStatement, args); | ||
|
||
return { |
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.
These extra object will cost. Let's simplify the interface to a plain array since we already have one.
@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. |
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