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

SQLx CLI: cargo sqlx prepare with SQLite doesn't do anything #1813

Closed
tobymurray opened this issue Apr 18, 2022 · 1 comment
Closed

SQLx CLI: cargo sqlx prepare with SQLite doesn't do anything #1813

tobymurray opened this issue Apr 18, 2022 · 1 comment

Comments

@tobymurray
Copy link
Contributor

Following the documentation here, I'm trying to create my sqlx-data.json but SQLx does not appear to find any of my queries.

I've just started using SQLx with SQLite, so I'm not sure if I'm doing something unexpected but I think it's a pretty mundane project. I have a handful of queries that generally look something like:

sqlx::query!(
  "
  UPDATE products
  SET deleted = TRUE
  WHERE store_name = $1
  ",
  store_name,
)
.fetch_all(db)
.await?;

Running the application works fine, I get errors when I build if the schema doesn't line up. Trying to build the file does not appear to do anything with either environment variables in a .env nor provided directly:

$ SQLX_OFFLINE=true DATABASE_URL=sqlite://sqlite/production.db cargo sqlx prepare
   Compiling project-name v0.1.0 (/home/toby/git/rust/project-name)
    Finished dev [unoptimized + debuginfo] target(s) in 9.55s
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

Yields a sqlx-data.json:

{
  "db": "SQLite"
}

Am I missing something obvious?

  • SQLx: 0.5.13
  • cargo-sqlx 0.5.13
  • SQLite3: 3.31.1
  • libsqlite3-sys: 0.24.2
@tobymurray
Copy link
Contributor Author

Has no effect unless the offline feature of sqlx is enabled in your project. Omitting that feature is the most likely cause if you get a sqlx-data.json file that looks like this:

I misunderstood this, I thought SQLX_OFFLINE=true was enabling the offline feature (feature as in "functionality") but "offline feature" in this context means a Cargo feature (as in specified in Cargo.toml).

Adding offline so my Cargo.toml looks like

sqlx = { version = "0.5", features = [ "runtime-tokio-native-tls" , "sqlite", "chrono", "offline" ] }

yields a populated file.

tobymurray added a commit to tobymurray/sqlx that referenced this issue Apr 18, 2022
Sometimes people do a bad job of reading comprehension (see launchbadge#1813). This rewords a little to be even more prescriptive about how to build in offline mode.
tobymurray added a commit to tobymurray/sqlx that referenced this issue Apr 18, 2022
Sometimes people do a bad job of reading comprehension (see launchbadge#1813). This rewords a little to be even more prescriptive about how to build in offline mode.
abonander pushed a commit that referenced this issue May 31, 2022
Sometimes people do a bad job of reading comprehension (see #1813). This rewords a little to be even more prescriptive about how to build in offline mode.
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