1

I'm trying to run postgres database in offline mode using the sqlx cli by running the command sqlx prepare to prepare the sqlx-data.json file to work offline per these instructions:

https://github.com/launchbadge/sqlx/blob/master/sqlx-cli/README.md#enable-building-in-offline-mode-with-query

I've set this environment variable SQLX_OFFLINE=true in my .env file and am getting the following error and am passing in the --database-url like so:

✦ ❯ cargo sqlx prepare -- --bin my-project --database-url postgres://postgres@localhost?db_name=postgres&user=postgres&password=postgres 
[1] 13748
[2] 13749
[2]+  Done                    user=postgres

✦2 ❯ error: The following required arguments were not provided:
    --database-url <database-url>

USAGE:
    cargo sqlx prepare <args>... --database-url <database-url>

For more information try --help
^C^C

I'm confused by this because the command seems to succeed, and then a few seconds later, I get an error message.

I'm explicitly asked to provide a bin and am wondering how to provide BOTH a database-url and a bin name. Seems like I can only work with one or the other, but am getting errors for both?

✦ ❯ 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
cargo sqlx prepare --database-url postgres://postgres@localhost?db_name=postgres&user=postgres&password=postgres
[1]+  Exit 1                  cargo sqlx prepare --database-url postgres://postgres@localhost?db_name=postgres
[1] 14236
[2] 14237
[2]+  Done                    user=postgres

✦2 ❯ 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
^C
[1]+  Exit 1                  cargo sqlx prepare --database-url postgres://postgres@localhost?db_name=postgres

Any help would be greatly appreciated. Thanks in advance!

smitop
  • 4,770
  • 2
  • 20
  • 53
AMP_035
  • 167
  • 1
  • 2
  • 13

1 Answers1

1

sqlx uses your .env file to parse the DATABASE_URL so you shouldn't need to pass it in when running cargo sqlx prepare if you have it set there.

wileybaba
  • 380
  • 1
  • 3
  • 11