diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 8c9fd17e..4c23912c 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -22,7 +22,7 @@ clap = { version = "^2.33.3" } dotenv = { version = "^0.15" } async-std = { version = "^1.9", features = [ "attributes" ] } sea-orm-codegen = { version = "^0.2.0", path = "../sea-orm-codegen" } -sea-schema = { version = "^0.2.7", git = "https://github.com/SeaQL/sea-schema.git", branch = "update-sea-query-version", default-features = false, features = [ +sea-schema = { version = "^0.2.7", git = "https://github.com/SeaQL/sea-schema.git", default-features = false, features = [ "sqlx-mysql", "sqlx-postgres", "discovery", diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index d328724d..de38c992 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -15,7 +15,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "^0.16.1", git = "https://github.com/SeaQL/sea-query.git", branch = "foreign-key-getters" } +sea-query = { version = "^0.16.2" } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", diff --git a/sea-orm-codegen/rustfmt.toml b/sea-orm-codegen/rustfmt.toml index 2555d91f..d7f6da65 100644 --- a/sea-orm-codegen/rustfmt.toml +++ b/sea-orm-codegen/rustfmt.toml @@ -1,3 +1,4 @@ ignore = [ - "tests/entity/*.rs", + "tests/compact/*.rs", + "tests/expanded/*.rs", ] \ No newline at end of file diff --git a/sea-orm-codegen/src/entity/column.rs b/sea-orm-codegen/src/entity/column.rs index fd8e1936..dfec4b8e 100644 --- a/sea-orm-codegen/src/entity/column.rs +++ b/sea-orm-codegen/src/entity/column.rs @@ -2,7 +2,6 @@ use heck::{CamelCase, SnakeCase}; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; use sea_query::{ColumnDef, ColumnSpec, ColumnType}; -use syn::punctuated::Punctuated; #[derive(Clone, Debug)] pub struct Column { @@ -59,6 +58,7 @@ impl Column { ColumnType::Double(Some(l)) => Some(format!("Double(Some({}))", l)), ColumnType::Decimal(Some((p, s))) => Some(format!("Decimal(Some(({}, {})))", p, s)), ColumnType::Money(Some((p, s))) => Some(format!("Money(Some({}, {}))", p, s)), + ColumnType::Text => Some("Text".to_owned()), ColumnType::Custom(iden) => { Some(format!("Custom(\"{}\".to_owned())", iden.to_string())) } diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 5a47ce4c..edfbef0b 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -1,7 +1,6 @@ use crate::Entity; use proc_macro2::TokenStream; use quote::quote; -use std::iter::FromIterator; use syn::{punctuated::Punctuated, token::Comma}; #[derive(Clone, Debug)] @@ -343,6 +342,9 @@ impl EntityWriter { } if let Some(ts) = col.get_col_type_attrs() { attrs.extend(vec![ts]); + if !col.not_null { + attrs.push(quote! { nullable }); + } }; if !attrs.is_empty() { let mut ts = TokenStream::new(); @@ -411,9 +413,9 @@ mod tests { }, Column { name: "name".to_owned(), - col_type: ColumnType::String(Some(255)), + col_type: ColumnType::Text, auto_increment: false, - not_null: true, + not_null: false, unique: false, }, ], diff --git a/sea-orm-codegen/tests/compact/cake.rs b/sea-orm-codegen/tests/compact/cake.rs index 4a64611e..2e26257c 100644 --- a/sea-orm-codegen/tests/compact/cake.rs +++ b/sea-orm-codegen/tests/compact/cake.rs @@ -7,7 +7,8 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub name: String, + #[sea_orm(column_type = "Text", nullable)] + pub name: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/sea-orm-codegen/tests/expanded/cake.rs b/sea-orm-codegen/tests/expanded/cake.rs index 55fa279f..0b33b618 100644 --- a/sea-orm-codegen/tests/expanded/cake.rs +++ b/sea-orm-codegen/tests/expanded/cake.rs @@ -14,7 +14,7 @@ impl EntityName for Entity { #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] pub struct Model { pub id: i32, - pub name: String, + pub name: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] @@ -46,7 +46,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::Text.def().null(), } } } diff --git a/sea-orm-macros/src/derives/entity_model.rs b/sea-orm-macros/src/derives/entity_model.rs index bd6b332d..66c5725f 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -163,7 +163,9 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res "bool" => quote! { Boolean }, "NaiveDate" => quote! { Date }, "NaiveTime" => quote! { Time }, - "DateTime" | "NaiveDateTime" | "DateTimeWithTimeZone" => quote! { DateTime }, + "DateTime" | "NaiveDateTime" | "DateTimeWithTimeZone" => { + quote! { DateTime } + } "Uuid" => quote! { Uuid }, "Json" => quote! { Json }, "Decimal" => quote! { Decimal },