SQLX

GitHub
GitHub - avsaase/sqlx-d1: WIP Cloudflare D1 driver for SQLx
WIP Cloudflare D1 driver for SQLx. Contribute to avsaase/sqlx-d1 development by creating an account on GitHub.
6 Replies
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
avsaase
avsaaseOP8mo ago
Yeah that's going to be tricky. AFAIK sqlx assumes thay you can connect to a dev database in the same way as to a prod database but that's obviously not going to work for D1. I think there's some more boilerplate needed for the compile-time query checking but I haven't looked at that yet. Perhaps there's a way to hack a connection to the REST API in there. It's been a while since I used sqlx and I don't recall the exact workflow when using it in a normal setting. How to handles transactions migrations is another question. Sqlx provides it's own cli to manage those but I'm not sure if that's mandatory.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
avsaase
avsaaseOP8mo ago
Oh right, When running locally wrangler creates normal sqlite files so those should be relatively easy to use. I'm not familiar with how D1 handles migrations. Are they automatically applied by wrangler?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
<Dominik/>
<Dominik/>8mo ago
I had the same idea. Theoretically you could use the local D1 (via miniflare probably?) to get the types. Tho getting this feature into the macro would probably rely on a rework of sqlx macro itself as proposed here: https://github.com/launchbadge/sqlx/issues/1598. Also detecting dev target is easy with cfg(debug_assertions) no?
GitHub
Issues · launchbadge/sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite. - Issues · launchbadge/sqlx
Want results from more Discord servers?
Add your server