4

I am using some sqlx::query! and sqlx::query_as! and my project compiles fine. But when I run cargo sqlx prepare I get first and error:

$ cargo sqlx prepare
error: extra arguments to `rustc` can only be passed to one target, consider filtering
the package by passing, e.g., `--lib` or `--bin NAME` to specify a single target
error: `cargo check` failed with status: exit status: 101

Then when I run it with "-- --lib" I get:

$ cargo sqlx prepare -- --lib
   Compiling crate v0.1.0 (/Users/ryan/Documents/crate)
    Finished dev [unoptimized + debuginfo] target(s) in 5.78s
warning: no queries found; please ensure that the `offline` feature is enabled in sqlx
query data written to `sqlx-data.json` in the current directory; please check this into version control

I get similar output with --bin.

What am I doing wrong here?

ryan
  • 51
  • 4
  • 1
    I also had the same issue. I guess there's some bug. I fixed it by running `cargo clean` and then running `cargo sqlx prepare -- --bin ` – Abhyudit Jain Sep 18 '21 at 04:34
  • `cargo clean` didn't work for me, I had to reinstall with `cargo install sqlx-cli --no-default-features --features native-tls,postgres`, then it worked as `cargo sqlx prepare`. – rsalmei Oct 15 '22 at 02:07
  • 1
    Also, make sure, that you using same version of `sqlx-cli` and `sqlx`, that you pointed as dependency of you package. – Vasiliy Stavenko Oct 21 '22 at 16:25

1 Answers1

6

Same case had before, but could find usefull information in their documentation. Rather than running only cargo sqlx prepare -- --lib, first reinstall sqlx-cli, like below:

cargo install sqlx-cli && cargo sqlx prepare -- --lib
  • having an old version of sqlx-cli installed may result in `query!`-macros are not extracted from the code, just saying like "did you switch the 'offline' feature on"? So `cargo install sqlx-cli` did it for me. – Aitch Feb 11 '23 at 12:36