-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the synchronize_schema method for ORM
- Loading branch information
Showing
17 changed files
with
179 additions
and
98 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::model::{Column, EncodeColumn}; | ||
|
||
/// Returns the column definition. | ||
pub(super) fn column_def(col: &Column, primary_key_name: &str) -> String { | ||
let column_name = col.name(); | ||
let column_type = col.column_type(); | ||
let mut definition = format!("{column_name} {column_type}"); | ||
if column_name == primary_key_name { | ||
definition += " PRIMARY KEY"; | ||
} else if let Some(value) = col.default_value() { | ||
if col.auto_increment() { | ||
definition += if cfg!(feature = "orm-mysql") { | ||
" AUTO_INCREMENT" | ||
} else { | ||
" AUTOINCREMENT" | ||
}; | ||
} else { | ||
let value = col.format_value(value); | ||
if cfg!(feature = "orm-sqlite") && value.contains('(') { | ||
definition = format!("{definition} DEFAULT ({value})"); | ||
} else { | ||
definition = format!("{definition} DEFAULT {value}"); | ||
} | ||
} | ||
} else if col.is_not_null() { | ||
definition += " NOT NULL"; | ||
} | ||
definition | ||
} |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ use std::{ | |
use toml::value::Table; | ||
|
||
mod accessor; | ||
mod column; | ||
mod decode; | ||
mod helper; | ||
mod mutation; | ||
|
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
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
Oops, something went wrong.