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

cargo sqlx prepare does not detect queries unless cargo clean is run first #1470

Closed
damccull opened this issue Oct 2, 2021 · 3 comments
Closed

Comments

@damccull
Copy link

damccull commented Oct 2, 2021

Whenever I try to run cargo sqlx prepare -- --bin mybin against a postgres database, it works only if I first do a cargo clean. Any other time it writes a mostly empty file (attached) and reports

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

Is this something wrong in the code or something wrong with how I'm doing it?

sqlx-data.txt

@abonander
Copy link
Collaborator

Try cargo sqlx prepare -- --lib

It sounds like you have all your query!() macros in the library portion of your crate. If Cargo doesn't need to rebuild that part then it won't execute the macros when you do cargo sqlx prepare -- --bin mybin.

This will be fixed by #570 which should be part of 0.6.0.

@damccull
Copy link
Author

damccull commented Oct 5, 2021

Yes, that was the issue. Is there currently a way to do both a bin and a library? I tried cargo prepare -- --lib --bin mybin but that's a no-go.

@damccull
Copy link
Author

damccull commented Oct 5, 2021

It seems that's not possible after some research. The args after -- apparently go to cargo rustc and it will not accept multiple targets, so I'll just make sure all queries live in the lib. Thanks a ton for your help @abonander.

@damccull damccull closed this as completed Oct 5, 2021
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

2 participants