-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: New Functionalities #13
Open
buraktabn
wants to merge
9
commits into
jayy-lmao:main
Choose a base branch
from
R3-Lab:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
74ed42c
changes for personalization
buraktabn db093c7
option to derive w serde
buraktabn 8b4e08b
create enums for user defined types
buraktabn 353bdc1
data types & date time lib
buraktabn 0451b8e
(fix) generated unique queries may have dup functions
buraktabn 56cf8c3
(fix) select by fk query code
buraktabn e568854
(fix) drop once_cell use std OnceLock
buraktabn 34936c3
(fix) added args for extra struct and enum derives
buraktabn 6393fe2
(fix) generate_select_by_fk_query_code
buraktabn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
use std::{collections::BTreeSet, sync::OnceLock}; | ||
|
||
use clap::{App, Arg, SubCommand}; | ||
use utils::{DateTimeLib, SqlGenState}; | ||
|
||
mod db_queries; | ||
mod generate; | ||
|
@@ -7,6 +10,8 @@ mod models; | |
mod query_generate; | ||
mod utils; | ||
|
||
pub(crate) static STATE: OnceLock<SqlGenState> = OnceLock::new(); | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
dotenv::dotenv().ok(); | ||
|
@@ -22,6 +27,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
.help("Sets the output folder for generated structs") | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("serde") | ||
.long("serde") | ||
.default_value("true") | ||
.value_name("SQLGEN_ENABLE_SERDE") | ||
.help("Adds Serde derices to created structs") | ||
.takes_value(false), | ||
) | ||
.arg( | ||
Arg::with_name("migrations") | ||
.short('m') | ||
|
@@ -68,6 +81,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
.use_delimiter(true) | ||
.help("Specify the table name(s)"), | ||
) | ||
.arg( | ||
Arg::with_name("exclude") | ||
.short('e') | ||
.long("exclude") | ||
.takes_value(true) | ||
.value_name("SQLGEN_EXCLUDE") | ||
.multiple(true) | ||
.use_delimiter(true) | ||
.help("Specify the excluded table name(s)"), | ||
) | ||
Comment on lines
+84
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great idea |
||
.arg( | ||
Arg::new("force") | ||
.short('f') | ||
|
@@ -76,6 +99,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
.takes_value(false) | ||
.required(false) | ||
.help("Overwrites existing files sharing names in that folder"), | ||
) | ||
.arg( | ||
Arg::with_name("datetime-lib") | ||
.long("datetime-lib") | ||
.default_value("chrono") | ||
.possible_values(&["chrono", "time"]) | ||
.value_name("SQLGEN_DATETIME_LIB") | ||
.help("Specifies the library to use for date and time handling") | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("struct-derive") | ||
.long("struct-derive") | ||
.value_name("SQLGEN_STRUCT_DERIVE") | ||
.help("Derive created structs with given values") | ||
.multiple(true) | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("enum-derive") | ||
.long("enum-derive") | ||
.value_name("SQLGEN_ENUM_DERIVE") | ||
.help("Derive created enums with given values") | ||
.multiple(true) | ||
.takes_value(true), | ||
); | ||
|
||
let migrate_subcommand = SubCommand::with_name("migrate") | ||
|
@@ -195,7 +243,74 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let schemas: Option<Vec<&str>> = | ||
matches.values_of("schema").map(|schemas| schemas.collect()); | ||
let force = matches.is_present("force"); | ||
generate::generate(output_folder, database_url, context, force, None, schemas).await?; | ||
let include_tables = matches.values_of("table").map(|v| v.collect::<Vec<&str>>()); | ||
let exclude_tables = matches | ||
.values_of("exclude") | ||
.map(|v| { | ||
v.into_iter() | ||
.map(|e| e.to_string()) | ||
.collect::<Vec<String>>() | ||
}) | ||
.unwrap_or(vec![]); | ||
|
||
if !exclude_tables.is_empty() { | ||
println!("Excluding tables: {:?}", exclude_tables); | ||
} | ||
|
||
let enable_serde = matches.is_present("serde"); | ||
let mut struct_derives = matches | ||
.values_of("struct-derive") | ||
.map(|v| { | ||
v.into_iter() | ||
.map(|e| e.to_string()) | ||
.collect::<Vec<String>>() | ||
}) | ||
.unwrap_or_default(); | ||
let mut enum_derives = matches | ||
.values_of("enum-derive") | ||
.map(|v| { | ||
v.into_iter() | ||
.map(|e| e.to_string()) | ||
.collect::<Vec<String>>() | ||
}) | ||
.unwrap_or_default(); | ||
|
||
if enable_serde { | ||
let mut unique_struct_derivies = struct_derives | ||
.clone() | ||
.into_iter() | ||
.collect::<BTreeSet<String>>(); | ||
let mut unique_enum_derivies = enum_derives | ||
.clone() | ||
.into_iter() | ||
.collect::<BTreeSet<String>>(); | ||
for serde_derive in ["serde::Serialize", "serde::Deserialize"] { | ||
unique_struct_derivies.insert(serde_derive.to_string()); | ||
unique_enum_derivies.insert(serde_derive.to_string()); | ||
} | ||
|
||
struct_derives = unique_struct_derivies.into_iter().collect(); | ||
enum_derives = unique_enum_derivies.into_iter().collect(); | ||
} | ||
let date_time_lib = matches | ||
.value_of("datetime-lib") | ||
.map(|e| e.to_string()) | ||
.unwrap(); | ||
let date_time_lib = DateTimeLib::from(date_time_lib); | ||
|
||
generate::generate( | ||
output_folder, | ||
database_url, | ||
context, | ||
force, | ||
include_tables, | ||
exclude_tables, | ||
schemas, | ||
date_time_lib, | ||
struct_derives, | ||
enum_derives, | ||
) | ||
.await?; | ||
} else if let Some(matches) = matches.subcommand_matches("migrate") { | ||
let input_migrations_folder = matches.value_of("migrations").unwrap_or("./migrations"); | ||
println!( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty for doing this 🙏