+
Skip to content

Codegen Unsigned Integer - 2 #397

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

Merged
merged 10 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" }
tracing = { version = "0.1", features = ["log"] }
rust_decimal = { version = "^1", optional = true }
sea-orm-macros = { version = "^0.6.0", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.21.0", features = ["thread-safe"] }
sea-query = { version = "^0.22.0", features = ["thread-safe"] }
sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clap = { version = "^2.33.3" }
dotenv = { version = "^0.15" }
async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] }
sea-orm-codegen = { version = "^0.6.0", path = "../sea-orm-codegen" }
sea-schema = { version = "^0.5.0", default-features = false, features = [
sea-schema = { version = "^0.6.0", default-features = false, features = [
"debug-print",
"sqlx-mysql",
"sqlx-sqlite",
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "sea_orm_codegen"
path = "src/lib.rs"

[dependencies]
sea-query = { version = "0.21.0" }
sea-query = { version = "0.22.0" }
syn = { version = "^1", default-features = false, features = [
"derive",
"parsing",
Expand Down
30 changes: 29 additions & 1 deletion sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl Column {
ColumnType::SmallInteger(_) => "i16".to_owned(),
ColumnType::Integer(_) => "i32".to_owned(),
ColumnType::BigInteger(_) => "i64".to_owned(),
ColumnType::TinyUnsigned(_) => "u8".to_owned(),
ColumnType::SmallUnsigned(_) => "u16".to_owned(),
ColumnType::Unsigned(_) => "u32".to_owned(),
ColumnType::BigUnsigned(_) => "u64".to_owned(),
ColumnType::Float(_) => "f32".to_owned(),
ColumnType::Double(_) => "f64".to_owned(),
ColumnType::Json | ColumnType::JsonBinary => "Json".to_owned(),
Expand Down Expand Up @@ -90,6 +94,10 @@ impl Column {
ColumnType::SmallInteger(_) => quote! { ColumnType::SmallInteger.def() },
ColumnType::Integer(_) => quote! { ColumnType::Integer.def() },
ColumnType::BigInteger(_) => quote! { ColumnType::BigInteger.def() },
ColumnType::TinyUnsigned(_) => quote! { ColumnType::TinyUnsigned.def() },
ColumnType::SmallUnsigned(_) => quote! { ColumnType::SmallUnsigned.def() },
ColumnType::Unsigned(_) => quote! { ColumnType::Unsigned.def() },
ColumnType::BigUnsigned(_) => quote! { ColumnType::BigUnsigned.def() },
ColumnType::Float(_) => quote! { ColumnType::Float.def() },
ColumnType::Double(_) => quote! { ColumnType::Double.def() },
ColumnType::Decimal(s) => match s {
Expand Down Expand Up @@ -194,9 +202,13 @@ mod tests {
ColumnType::Custom(SeaRc::new(Alias::new("cus_col")))
),
make_col!("CakeId", ColumnType::TinyInteger(None)),
make_col!("CakeId", ColumnType::TinyUnsigned(Some(9))),
make_col!("CakeId", ColumnType::SmallInteger(None)),
make_col!("CakeId", ColumnType::Integer(Some(11))),
make_col!("CakeId", ColumnType::SmallUnsigned(Some(10))),
make_col!("CakeId", ColumnType::Integer(None)),
make_col!("CakeId", ColumnType::Unsigned(Some(11))),
make_col!("CakeFillingId", ColumnType::BigInteger(None)),
make_col!("CakeFillingId", ColumnType::BigUnsigned(Some(12))),
make_col!("cake-filling-id", ColumnType::Float(None)),
make_col!("CAKE_FILLING_ID", ColumnType::Double(None)),
make_col!("CAKE-FILLING-ID", ColumnType::Binary(None)),
Expand All @@ -218,6 +230,10 @@ mod tests {
"cake_id",
"cake_id",
"cake_id",
"cake_id",
"cake_id",
"cake_id",
"cake_filling_id",
"cake_filling_id",
"cake_filling_id",
"cake_filling_id",
Expand All @@ -243,6 +259,10 @@ mod tests {
"CakeId",
"CakeId",
"CakeId",
"CakeId",
"CakeId",
"CakeId",
"CakeFillingId",
"CakeFillingId",
"CakeFillingId",
"CakeFillingId",
Expand All @@ -266,9 +286,13 @@ mod tests {
"String",
"String",
"i8",
"u8",
"i16",
"u16",
"i32",
"u32",
"i64",
"u64",
"f32",
"f64",
"Vec<u8>",
Expand Down Expand Up @@ -300,9 +324,13 @@ mod tests {
"ColumnType::String(Some(255u32)).def()",
"ColumnType::Custom(\"cus_col\".to_owned()).def()",
"ColumnType::TinyInteger.def()",
"ColumnType::TinyUnsigned.def()",
"ColumnType::SmallInteger.def()",
"ColumnType::SmallUnsigned.def()",
"ColumnType::Integer.def()",
"ColumnType::Unsigned.def()",
"ColumnType::BigInteger.def()",
"ColumnType::BigUnsigned.def()",
"ColumnType::Float.def()",
"ColumnType::Double.def()",
"ColumnType::Binary.def()",
Expand Down
14 changes: 7 additions & 7 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,28 +780,28 @@ mod tests {
},
Column {
name: "testing".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::TinyInteger(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "rust".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::TinyUnsigned(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "keywords".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::SmallInteger(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "type".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::SmallUnsigned(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
Expand All @@ -815,21 +815,21 @@ mod tests {
},
Column {
name: "crate".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::Unsigned(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "self".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::BigInteger(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "self_id1".to_owned(),
col_type: ColumnType::Integer(Some(11)),
col_type: ColumnType::BigUnsigned(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
Expand Down
14 changes: 7 additions & 7 deletions sea-orm-codegen/tests/compact/rust_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub testing: i32,
pub rust: i32,
pub keywords: i32,
pub r#type: i32,
pub testing: i8,
pub rust: u8,
pub keywords: i16,
pub r#type: u16,
pub r#typeof: i32,
pub crate_: i32,
pub self_: i32,
pub self_id1: i32,
pub crate_: u32,
pub self_: i64,
pub self_id1: u64,
pub self_id2: i32,
pub fruit_id1: i32,
pub fruit_id2: i32,
Expand Down
28 changes: 14 additions & 14 deletions sea-orm-codegen/tests/expanded/rust_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ impl EntityName for Entity {
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
pub id: i32,
pub testing: i32,
pub rust: i32,
pub keywords: i32,
pub r#type: i32,
pub testing: i8,
pub rust: u8,
pub keywords: i16,
pub r#type: u16,
pub r#typeof: i32,
pub crate_: i32,
pub self_: i32,
pub self_id1: i32,
pub crate_: u32,
pub self_: i64,
pub self_id1: u64,
pub self_id2: i32,
pub fruit_id1: i32,
pub fruit_id2: i32,
Expand Down Expand Up @@ -73,14 +73,14 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Testing => ColumnType::Integer.def(),
Self::Rust => ColumnType::Integer.def(),
Self::Keywords => ColumnType::Integer.def(),
Self::Type => ColumnType::Integer.def(),
Self::Testing => ColumnType::TinyInteger.def(),
Self::Rust => ColumnType::TinyUnsigned.def(),
Self::Keywords => ColumnType::SmallInteger.def(),
Self::Type => ColumnType::SmallUnsigned.def(),
Self::Typeof => ColumnType::Integer.def(),
Self::Crate => ColumnType::Integer.def(),
Self::Self_ => ColumnType::Integer.def(),
Self::SelfId1 => ColumnType::Integer.def(),
Self::Crate => ColumnType::Unsigned.def(),
Self::Self_ => ColumnType::BigInteger.def(),
Self::SelfId1 => ColumnType::BigUnsigned.def(),
Self::SelfId2 => ColumnType::Integer.def(),
Self::FruitId1 => ColumnType::Integer.def(),
Self::FruitId2 => ColumnType::Integer.def(),
Expand Down
12 changes: 8 additions & 4 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
let col_type = match temp {
"char" => quote! { Char(None) },
"String" | "&str" => quote! { String(None) },
"u8" | "i8" => quote! { TinyInteger },
"u16" | "i16" => quote! { SmallInteger },
"u32" | "i32" => quote! { Integer },
"u64" | "i64" => quote! { BigInteger },
"i8" => quote! { TinyInteger },
"u8" => quote! { TinyUnsigned },
"i16" => quote! { SmallInteger },
"u16" => quote! { SmallUnsigned },
"i32" => quote! { Integer },
"u32" => quote! { Unsigned },
"i64" => quote! { BigInteger },
"u64" => quote! { BigUnsigned },
"f32" => quote! { Float },
"f64" => quote! { Double },
"bool" => quote! { Boolean },
Expand Down
55 changes: 49 additions & 6 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub enum ColumnType {
/// `BIGINT` is a 64-bit representation of an integer taking up 8 bytes of storage and
/// ranging from -2^63 (-9,223,372,036,854,775,808) to 2^63 (9,223,372,036,854,775,807).
BigInteger,
/// `TINYINT UNSIGNED` data type
TinyUnsigned,
/// `SMALLINT UNSIGNED` data type
SmallUnsigned,
/// `INTEGER UNSIGNED` data type
Unsigned,
/// `BIGINT UNSIGNED` data type
BigUnsigned,
/// `FLOAT` an approximate-number data type, where values range cannot be represented exactly.
Float,
/// `DOUBLE` is a normal-size floating point number where the
Expand Down Expand Up @@ -362,6 +370,10 @@ impl From<ColumnType> for sea_query::ColumnType {
ColumnType::SmallInteger => sea_query::ColumnType::SmallInteger(None),
ColumnType::Integer => sea_query::ColumnType::Integer(None),
ColumnType::BigInteger => sea_query::ColumnType::BigInteger(None),
ColumnType::TinyUnsigned => sea_query::ColumnType::TinyUnsigned(None),
ColumnType::SmallUnsigned => sea_query::ColumnType::SmallUnsigned(None),
ColumnType::Unsigned => sea_query::ColumnType::Unsigned(None),
ColumnType::BigUnsigned => sea_query::ColumnType::BigUnsigned(None),
ColumnType::Float => sea_query::ColumnType::Float(None),
ColumnType::Double => sea_query::ColumnType::Double(None),
ColumnType::Decimal(s) => sea_query::ColumnType::Decimal(s),
Expand Down Expand Up @@ -395,6 +407,10 @@ impl From<sea_query::ColumnType> for ColumnType {
sea_query::ColumnType::SmallInteger(_) => Self::SmallInteger,
sea_query::ColumnType::Integer(_) => Self::Integer,
sea_query::ColumnType::BigInteger(_) => Self::BigInteger,
sea_query::ColumnType::TinyUnsigned(_) => Self::TinyUnsigned,
sea_query::ColumnType::SmallUnsigned(_) => Self::SmallUnsigned,
sea_query::ColumnType::Unsigned(_) => Self::Unsigned,
sea_query::ColumnType::BigUnsigned(_) => Self::BigUnsigned,
sea_query::ColumnType::Float(_) => Self::Float,
sea_query::ColumnType::Double(_) => Self::Double,
sea_query::ColumnType::Decimal(s) => Self::Decimal(s),
Expand Down Expand Up @@ -513,13 +529,21 @@ mod tests {
pub id: i32,
pub one: i32,
#[sea_orm(unique)]
pub two: i32,
pub two: i8,
#[sea_orm(indexed)]
pub three: i32,
pub three: i16,
#[sea_orm(nullable)]
pub four: i32,
#[sea_orm(unique, indexed, nullable)]
pub five: i32,
pub five: i64,
#[sea_orm(unique)]
pub six: u8,
#[sea_orm(indexed)]
pub seven: u16,
#[sea_orm(nullable)]
pub eight: u32,
#[sea_orm(unique, indexed, nullable)]
pub nine: u64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -529,18 +553,37 @@ mod tests {
}

assert_eq!(hello::Column::One.def(), ColumnType::Integer.def());
assert_eq!(hello::Column::Two.def(), ColumnType::Integer.def().unique());
assert_eq!(
hello::Column::Two.def(),
ColumnType::TinyInteger.def().unique()
);
assert_eq!(
hello::Column::Three.def(),
ColumnType::Integer.def().indexed()
ColumnType::SmallInteger.def().indexed()
);
assert_eq!(
hello::Column::Four.def(),
ColumnType::Integer.def().nullable()
);
assert_eq!(
hello::Column::Five.def(),
ColumnType::Integer.def().unique().indexed().nullable()
ColumnType::BigInteger.def().unique().indexed().nullable()
);
assert_eq!(
hello::Column::Six.def(),
ColumnType::TinyUnsigned.def().unique()
);
assert_eq!(
hello::Column::Seven.def(),
ColumnType::SmallUnsigned.def().indexed()
);
assert_eq!(
hello::Column::Eight.def(),
ColumnType::Unsigned.def().nullable()
);
assert_eq!(
hello::Column::Nine.def(),
ColumnType::BigUnsigned.def().unique().indexed().nullable()
);
}

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载