Add "--include-hidden-tables" flag

This commit is contained in:
Billy Chan 2021-08-11 11:00:06 +08:00 committed by Chris Tsang
parent 10d670e472
commit 1765ac953b
2 changed files with 16 additions and 0 deletions

View File

@ -34,6 +34,12 @@ pub fn build_cli() -> App<'static, 'static> {
.help("Entity file output directory")
.takes_value(true)
.default_value("./"),
)
.arg(
Arg::with_name("INCLUDE_HIDDEN_TABLES")
.long("include-hidden-tables")
.help("Generate entity file for hidden tables (i.e. table name starts with an underscore)")
.takes_value(false),
),
)
.setting(AppSettings::SubcommandRequiredElseHelp);

View File

@ -24,6 +24,14 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
("entity", Some(args)) => {
let url = args.value_of("DATABASE_URL").unwrap();
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
let include_hidden_tables = args.is_present("INCLUDE_HIDDEN_TABLES");
let filter_hidden_tables = |table: &str| -> bool {
if include_hidden_tables {
true
} else {
!table.starts_with("_")
}
};
let table_stmts = if url.starts_with("mysql://") {
use sea_schema::mysql::discovery::SchemaDiscovery;
@ -37,6 +45,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
schema
.tables
.into_iter()
.filter(|schema| filter_hidden_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
} else if url.starts_with("postgres://") {
@ -50,6 +59,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
schema
.tables
.into_iter()
.filter(|schema| filter_hidden_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
} else {