I am having a problem using relative path with sqlx and sqlite.
My workspace looks like this:
workspace/
Cargo.toml
.env
base_dir/
db.sqlite
binary_crate/
src/
main.rs
Using sqlx::query!
macro in main.rs
is marked red in vscode, hovering show:
error returned from database: (code: 14) unable to open database file
Which also occurs when executing cargo sqlx prepare
in binary_crate/
directory:
error: error returned from database: (code: 14) unable to open database file
--> binary_cratesrcmain.rs:21:20
|
21 | let user = sqlx::query!(
...
28 | | )
| |_________^
|
= note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)
I think this problem occurs due to sqlx issue #3099: SQLite+Macros: relative paths for database files are resolved inconsistently.
Setting DATABASE_URL
like in this workaround didn’t result in any noticeable change:
DATABASE_URL="sqlite://${CARGO_MANIFEST_DIR}/base_dir/db.sqlite"
How to workaround issue #3309 and use sqlite with relative path? OS is Windows 10.