Remix.run Logo
ilbert 4 hours ago

I actually took a lot of inspiration from sqlx, which is really nice. The main differences are:

- in JS/TS you don't have compile-time scripts that you can run like with Rust's macros, so you need to run a codegen command before running the type checks (disadvantage)

- I had to create a TS parser that goes and finds the tagged template functions with the sql statements, while sqlx has them "for free" because sql statements are the input to the macro itself (disadvantage)

- I use an in-memory Postgres (PGLite) to describe the queries, instead of requiring a running pg instance (advantage)

- I don't cache the statements and codegen for now like sqlx does, something that can be added later

I think they are similar in that they both substitute the dynamic params with no-ops like $1, $2, etc. before handing the sql statement to the pg's DESCRIBE function

trollbridge an hour ago | parent [-]

Very interesting! I spent a long session in a harness the other day getting pglite to the point it would work reliably in a browser for a specific use case I had. The key was NOT using that environment to run the SQLx validation, but just having a real long running Postgres for local builds + CI, and simply creating and dropping a database for that run.

Used pglite-oxide for the Electron build and then we went off into the weeds and ported pglite so it could run in iOS for iOS apps. The easiest way to do this is to just do it as a plain old Mac app first and get it working there first.

I’ll open source this if I figure out if we can maintain it and document it.