Skip to content

Issue with SQLx and Sqlite when using ORDER BY and LIMIT

Notifications You must be signed in to change notification settings

0rvar/sqlx-sqlite-option-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Issue with SQLx and Sqlite when using ORDER BY and LIMIT

This is a minimal example of an issue I'm having with SQLx and Sqlite when using ORDER BY and LIMIT. SQLx incorrectly decides that NOT NULL fields should map to Option<T>.

Using git bisect, I found that this issue was introduced in commit ed566225.

Run reproduction

cargo sqlx database setup
cargo build

Result

The build fails with below error, even though all fields in the table are declared as NOT NULL. Removing either ORDER BY or LIMIT will make the build succeed.

error[E0308]: mismatched types
  --> src/main.rs:18:16
   |
18 |       let foos = sqlx::query_as!(
   |  ________________^
19 | |         Foo,
20 | |         r#"
21 | |             SELECT *
...  |
26 | |         10
27 | |     )
   | |_____^ expected struct `String`, found enum `Option`
   = note: expected struct `String`
                found enum `Option<String>`
   = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> src/main.rs:18:16
   |
18 |       let foos = sqlx::query_as!(
   |  ________________^
19 | |         Foo,
20 | |         r#"
21 | |             SELECT *
...  |
26 | |         10
27 | |     )
   | |_____^ expected struct `NaiveDateTime`, found enum `Option`
   |
   = note: expected struct `NaiveDateTime`
                found enum `Option<NaiveDateTime>`
   = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

About

Issue with SQLx and Sqlite when using ORDER BY and LIMIT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published