-
Notifications
You must be signed in to change notification settings - Fork 48
Add initial TrailBase integration and tests. #228
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
base: main
Are you sure you want to change the base?
Conversation
|
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.
Looking good!
BTW, thinking about this PR made me realize we really should have collection types be in their own packages so e.g. if you want to do a major release you can #235
We'll be migrating the other packages in the next day or two so you can just move this PR to create a new package.
Sounds good. I was thinking the same, let alone when adding the backend-specific dependency.
If I understood correctly, we'll table this review until the split has happened for me to rebase? Sounds good, just ping this PR and I'll get the train rolling. Did you think about the example, should we handle it in a follow-up? Thanks! |
The refactor is merged so you can now move your code to a |
Awesome! Moved to separate package. |
Great! I also refactored the example so you can easily add a trail base version. Could you look at doing that? The docker backend perhaps could have a trail base setup too? |
Sure can do. Quick questions:
|
Yeah same example. It's meant to be an omnibus example so easily see every collection type. And yes, one command to start all of them. And yes in this pr as that'll make it easier to test. |
I added TrailBase to the example. I tried to fumble my way through...
|
hmm interesting — you're using the zod schemas from drizzle it looks like? So you should use zod schemas consistent with the trailblaze schema? I suppose you can't have Date types w/ sqlite? |
That my understanding, at first I tried to make mine compatible because I didn't necessarily want to change the downstream code.
I guess so.
SQLite has a DATETIME type, which internally is just an INT64. That said, for type-safety reasons TrailBase requires STRICT mode (see migrations), which doesn't allow DATETIME. W/o STRICT, types are merely affinities and SQLite let's you stick any value into any column :) |
Ok — yeah the other collections serialize & deserialize to/from Date objects — I imagine most people might want that for Trailblaze? Perhaps you could add a |
That's an interesting proposal. I would certainly love not to to diverge the downstream code of the example. Could you elaborate a bit how this could look like, is there any precedent for me to look at? Thanks EDIT: Would this just be two functions: parser: (record: Record) -> TItem,
serialize: (item: TItem) -. Record, ? If so, yeah, yeah I'll do that. It will certainly be a good starting point. |
Ok, I found
INTEGER as opposed to PG TIMESTAMPZ .
Anyway, it works now 🎉 . Do you think this is a workable starting point? |
Nice! Yeah, parsing/serializing the whole row works — perhaps doing it per column would be better though as for big tables, it'd be tedious to have to pass through all the untouched stuff. Electric has a parser by pg type as you found. |
I like that, I'm just not sure my TS foo is strong enough. I'm aware that it can render Doom, but how would I define/infer a type type TItem = {
id: string;
created: Date;
}
type TRecord = {
id: string;
created: number;
}
type Parse = {
id?: (id: string) => string;
created: (id: number) => Date;
}
function parse(parse: Parse, record: Partial<TRecord> | Record) : Partial<TItem> | TItem; Instead I rewrote the serialize/parse implementations to only explicit set the relevant fields. Do you think this could be a workable starting point? {
parse: (record: Todo): SelectTodo => ({
...record,
created_at: new Date(record.created_at * 1000),
updated_at: new Date(record.updated_at * 1000),
}),
}
My bad. Fixed TrailBase-TanstackDB.mp4 |
…changing downstream example code.
I've also started working on an example, as you suggested, but wanted to send out an RFC early.
Don't hold back. Let me know if this is going roughly the expected direction. If so, also let me know how you'd like to handle a potential example, e.g. should it be part of the same PR, should it be a full replica of the todo example?
Thanks!