Skip to content

Commit

Permalink
use null override for custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
NyxCode committed Sep 8, 2024
1 parent 3771d9a commit 74ac8f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example-postgres/migrations/20240908062042_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE users
last_name VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL UNIQUE,
role user_role NOT NULL,
type account_type NOT NULL,
type account_type,
"group" user_group NOT NULL DEFAULT 'local',
disabled TEXT,
last_login TIMESTAMP DEFAULT NULL
Expand Down
17 changes: 14 additions & 3 deletions example-postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ async fn main() -> anyhow::Result<()> {

let db = PgPool::connect(&dotenv::var("DATABASE_URL")?).await?;

log::info!("insert a new row into the database");
log::info!("insert a few new rows into the database");
let mut new = InsertUser {
user_id: 1,
first_name: "Moritz".to_owned(),
last_name: "Bischof".to_owned(),
email: "moritz.bischof1@gmail.com".to_owned(),
disabled: None,
role: Role::User,
ty: AccountType::Normal,
ty: Some(AccountType::Normal),
}
.insert(&db)
.await?;
InsertUser {
user_id: 2,
first_name: "Dylan".to_owned(),
last_name: "Thomas".to_owned(),
email: "dylan.thomas@gmail.com".to_owned(),
disabled: Some("email not verified".to_owned()),
role: Role::Admin,
ty: None,
}
.insert(&db)
.await?;
Expand Down Expand Up @@ -82,7 +93,7 @@ struct User {
#[ormx(custom_type)]
role: Role,
#[ormx(column = "type", custom_type)]
ty: AccountType,
ty: Option<AccountType>,
#[ormx(custom_type, default, set)]
group: UserGroup,
disabled: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion ormx-macros/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<B: Backend> TableField<B> {

if self.custom_type {
format!(
"{q}{}{q} AS {q}{}: {}{q}",
"{q}{}{q} AS {q}{}!: {}{q}",
self.column_name,
self.field.to_string(),
self.ty.to_token_stream()
Expand Down

0 comments on commit 74ac8f7

Please sign in to comment.