SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.94k stars 483 forks source link

Compile time checked Raw SQL #544

Closed johannescpk closed 2 years ago

johannescpk commented 2 years ago

Summary

Currently Raw SQL isn't compile time checked, but since sea-orm builds on sqlx, which has compile time checks as its main feature, it would be great to allow those in sea-orm as well.

Motivation

Compile time checks for raw sql give confidence and help you to not break things when writing SQL.

Additional Information

Not sure if this is even feasible with sea-orm.

billy1624 commented 2 years ago

Hey @johannescpk, thanks for the suggestions!

I guess you are talking about this?

For SeaORM, it does not force user to provide environment variable of DATABASE_URL at build time (compile time). However, to use sqlx::query! it was a must, as stated on the SQLx docs.

The DATABASE_URL environment variable must be set at build-time to point to a database server with the schema that the query string will be checked against. All variants of query!() use [dotenv] so this can be in a .env file instead.

Extracted from https://docs.rs/sqlx/0.5.11/sqlx/macro.query.html#requirements

kate-shine commented 2 years ago

There's also the offline mode https://docs.rs/sqlx/0.5.11/sqlx/macro.query.html#offline-mode-requires-the-offline-feature It is true that giving this feature to users would force them to have either of those two.

On the other hand, compile time checked queries are one of biggest advantages sqlx has, and exposing that feature for raw queries in SeaORM would be really nice :) Hiding it behind feature would make it easy for users who don't care about raw queries at all to ignore those requirements. (Technically, it should be also possible to generate the offline file sqlx-data.json from migrations)