Skip to content
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

Check SQL queries at compile time #3

Open
Luflosi opened this issue Apr 9, 2024 · 0 comments
Open

Check SQL queries at compile time #3

Luflosi opened this issue Apr 9, 2024 · 0 comments

Comments

@Luflosi
Copy link
Owner

Luflosi commented Apr 9, 2024

It would be nice to verify the queries at compile time.
However I found this to have too many papercuts for my taste.
Here are my reasons for not verifying the queries at compile-time with SQLx:

  • Can't indent the SQL queries nicely using the indoc! macro
  • The database needs to already exist while compiling, requiring extra steps
  • SQLx doesn't know that INTEGER PRIMARY KEY always implies NOT NULL so the inferred datatype is <Option<i64> instead of i64. This could be worked around by explicitly adding NOT NULL but I don't want to add meaningless code
  • The following code does not compile because two parameters are expected while I think only one should be required:
    let _ = sqlx::query!("
    INSERT OR IGNORE INTO zones (name) VALUES (?1);
    SELECT id FROM zones WHERE name = ?1;
    ", zone).fetch_one(conn).await?;

If at least two of these issues can be resolved, I'd be willing to implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant