Update CLI generate entity schema argument behavior
This commit is contained in:
parent
ff8d921343
commit
10d670e472
@ -9,5 +9,9 @@ cargo run -- -h
|
||||
Running Entity Generator:
|
||||
|
||||
```sh
|
||||
cargo run -- generate entity -u mysql://sea:sea@localhost/bakery -s bakery -o out
|
||||
# MySQL (`--database-schema` option is ignored)
|
||||
cargo run -- generate entity -u mysql://sea:sea@localhost/bakery -o out
|
||||
|
||||
# PostgreSQL
|
||||
cargo run -- generate entity -u postgres://sea:sea@localhost/bakery -s public -o out
|
||||
```
|
||||
|
@ -21,8 +21,10 @@ pub fn build_cli() -> App<'static, 'static> {
|
||||
.long("database-schema")
|
||||
.short("s")
|
||||
.help("Database schema")
|
||||
.long_help("Database schema\n \
|
||||
- For MySQL, this argument is ignored.\n \
|
||||
- For PostgreSQL, this argument is optional with default value 'public'.")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.env("DATABASE_SCHEMA"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -23,13 +23,14 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
match matches.subcommand() {
|
||||
("entity", Some(args)) => {
|
||||
let url = args.value_of("DATABASE_URL").unwrap();
|
||||
let schema = args.value_of("DATABASE_SCHEMA").unwrap();
|
||||
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
|
||||
|
||||
let table_stmts = if url.starts_with("mysql://") {
|
||||
use sea_schema::mysql::discovery::SchemaDiscovery;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
let url_parts: Vec<&str> = url.split("/").collect();
|
||||
let schema = url_parts.last().unwrap();
|
||||
let connection = MySqlPool::connect(url).await?;
|
||||
let schema_discovery = SchemaDiscovery::new(connection, schema);
|
||||
let schema = schema_discovery.discover().await;
|
||||
@ -42,6 +43,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
use sea_schema::postgres::discovery::SchemaDiscovery;
|
||||
use sqlx::PgPool;
|
||||
|
||||
let schema = args.value_of("DATABASE_SCHEMA").unwrap_or("public");
|
||||
let connection = PgPool::connect(url).await?;
|
||||
let schema_discovery = SchemaDiscovery::new(connection, schema);
|
||||
let schema = schema_discovery.discover().await;
|
||||
|
Loading…
x
Reference in New Issue
Block a user