mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-02-14 20:07:31 +00:00
Add --database-url to command line
This commit is contained in:
parent
dfb096eaa7
commit
2ec5ff06b0
@ -17,7 +17,7 @@ $ cargo install --version=0.1.0-beta.1 sqlx-cli --no-default-features --features
|
||||
|
||||
### Usage
|
||||
|
||||
All commands require `DATABASE_URL` to be set, either in the environment or in a `.env` file
|
||||
All commands require that a database url is provided. This can be done either with the `--database-url` command line option or by setting `DATABASE_URL`, either in the environment or in a `.env` file
|
||||
in the current working directory.
|
||||
|
||||
`database` and `migrate` subcommands support only Postgres; MySQL and SQLite are TODO.
|
||||
|
||||
@ -15,8 +15,11 @@ pub use crate::opt::Opt;
|
||||
pub async fn run(opt: Opt) -> anyhow::Result<()> {
|
||||
dotenv().ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL")
|
||||
.map_err(|_| anyhow!("The DATABASE_URL environment variable must be set"))?;
|
||||
let database_url = match opt.database_url {
|
||||
Some(db_url) => db_url,
|
||||
None => env::var("DATABASE_URL")
|
||||
.map_err(|_| anyhow!("The DATABASE_URL environment variable must be set"))?,
|
||||
};
|
||||
|
||||
match opt.command {
|
||||
Command::Migrate(migrate) => match migrate.command {
|
||||
|
||||
@ -4,6 +4,9 @@ use clap::Clap;
|
||||
pub struct Opt {
|
||||
#[clap(subcommand)]
|
||||
pub command: Command,
|
||||
|
||||
#[clap(short = "D", long)]
|
||||
pub database_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user