[cli] skip generating entity for ignored tables (#837)

This commit is contained in:
Billy Chan 2022-07-05 01:19:36 +08:00 committed by GitHub
parent d6831e5295
commit e0eb8ecf69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -111,6 +111,16 @@ pub enum GenerateSubcommands {
)]
tables: Option<String>,
#[clap(
value_parser,
long,
use_value_delimiter = true,
takes_value = true,
default_value = "seaql_migrations",
help = "Skip generating entity file for specified tables (comma separated)"
)]
ignore_tables: Vec<String>,
#[clap(
value_parser,
long,

View File

@ -17,6 +17,7 @@ pub async fn run_generate_command(
expanded_format,
include_hidden_tables,
tables,
ignore_tables,
max_connections,
output_dir,
database_schema,
@ -87,6 +88,10 @@ pub async fn run_generate_command(
}
};
let filter_skip_tables = |table: &String| -> bool {
!ignore_tables.contains(table)
};
let database_name = if !is_sqlite {
// The database name should be the first element of the path string
//
@ -130,6 +135,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.info.name))
.filter(|schema| filter_hidden_tables(&schema.info.name))
.filter(|schema| filter_skip_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
}
@ -145,6 +151,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.name))
.filter(|schema| filter_hidden_tables(&schema.name))
.filter(|schema| filter_skip_tables(&schema.name))
.map(|schema| schema.write())
.collect()
}
@ -161,6 +168,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.info.name))
.filter(|schema| filter_hidden_tables(&schema.info.name))
.filter(|schema| filter_skip_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
}