SQLite type mappings (#2077)
* sqlite: deps * sqlite: update data type mappings * sqlite: decimal test cases * sqlite: try negative numbers * fixup * fixup * fmt * clippy * fixup * fixup * fixup * refactor * fix * Drop the use of `rust_decimal_macros` (#2078) * sqlite: decimal -> real * revert * Bump dependencies * Fixup * Fixup * Fixup * Fixup * Refactor * Refactor * Refactor
This commit is contained in:
parent
7f25da3e2b
commit
cef380b977
@ -34,8 +34,8 @@ tracing = { version = "0.1", default-features = false, features = ["attributes",
|
||||
rust_decimal = { version = "1", default-features = false, optional = true }
|
||||
bigdecimal = { version = "0.3", default-features = false, optional = true }
|
||||
sea-orm-macros = { version = "0.12.12", path = "sea-orm-macros", default-features = false, features = ["strum"] }
|
||||
sea-query = { version = "0.30.4", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
|
||||
sea-query-binder = { version = "0.5.0", default-features = false, optional = true }
|
||||
sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
|
||||
sea-query-binder = { version = "0.6.0-rc.1", default-features = false, optional = true }
|
||||
strum = { version = "0.25", default-features = false }
|
||||
serde = { version = "1.0", default-features = false }
|
||||
serde_json = { version = "1.0", default-features = false, optional = true }
|
||||
|
@ -55,7 +55,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
Self::CakeId => ColumnType::Integer.def(),
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
#[sea_orm(column_type = "Decimal(Some((19, 4)))")]
|
||||
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
|
||||
pub price: Decimal,
|
||||
pub bakery_id: Option<i32>,
|
||||
pub gluten_free: i8,
|
||||
|
@ -8,7 +8,7 @@ pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
#[sea_orm(column_type = "Decimal(Some((19, 4)))")]
|
||||
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
|
||||
pub price: Decimal,
|
||||
pub bakery_id: Option<i32>,
|
||||
pub gluten_free: i8,
|
||||
|
@ -18,7 +18,7 @@ impl MigrationTrait for Migration {
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Cake::Name).string().not_null())
|
||||
.col(ColumnDef::new(Cake::Price).decimal_len(19, 4).not_null())
|
||||
.col(ColumnDef::new(Cake::Price).decimal_len(16, 4).not_null())
|
||||
.col(ColumnDef::new(Cake::BakeryId).integer())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
|
||||
#[sea_orm(rs_type = "String", db_type = "string(Some(1))")]
|
||||
pub enum Category {
|
||||
#[sea_orm(string_value = "B")]
|
||||
Big,
|
||||
|
@ -55,7 +55,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
Self::VendorId => ColumnType::Integer.def().nullable(),
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
||||
dotenvy = { version = "0.15", default-features = false, optional = true }
|
||||
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true }
|
||||
sea-orm-codegen = { version = "=0.12.12", path = "../sea-orm-codegen", default-features = false, optional = true }
|
||||
sea-schema = { version = "0.14.2" }
|
||||
sea-schema = { version = "0.15.0-rc.1" }
|
||||
sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true }
|
||||
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
|
||||
tracing = { version = "0.1", default-features = false }
|
||||
|
@ -17,7 +17,7 @@ name = "sea_orm_codegen"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
sea-query = { version = "0.30.0", default-features = false, features = ["thread-safe"] }
|
||||
sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe"] }
|
||||
syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] }
|
||||
quote = { version = "1", default-features = false }
|
||||
heck = { version = "0.4", default-features = false }
|
||||
|
@ -284,7 +284,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "name".to_owned(),
|
||||
col_type: ColumnType::String(None),
|
||||
col_type: ColumnType::string(None),
|
||||
auto_increment: false,
|
||||
not_null: false,
|
||||
unique: false,
|
||||
|
@ -2,7 +2,7 @@ use crate::{util::escape_rust_keyword, DateTimeCrate};
|
||||
use heck::{ToSnakeCase, ToUpperCamelCase};
|
||||
use proc_macro2::{Ident, TokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
use sea_query::{BlobSize, ColumnDef, ColumnSpec, ColumnType};
|
||||
use sea_query::{ColumnDef, ColumnSpec, ColumnType, StringLen};
|
||||
use std::fmt::Write as FmtWrite;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -96,14 +96,12 @@ impl Column {
|
||||
ColumnType::Text => Some("Text".to_owned()),
|
||||
ColumnType::JsonBinary => Some("JsonBinary".to_owned()),
|
||||
ColumnType::Custom(iden) => Some(format!("custom(\"{}\")", iden.to_string())),
|
||||
ColumnType::Binary(BlobSize::Blob(None)) => Some("Binary(BlobSize::Blob(None))".into()),
|
||||
ColumnType::Binary(BlobSize::Blob(Some(s))) => {
|
||||
Some(format!("Binary(BlobSize::Blob(Some({s})))"))
|
||||
}
|
||||
ColumnType::Binary(BlobSize::Tiny) => Some("Binary(BlobSize::Tiny)".into()),
|
||||
ColumnType::Binary(BlobSize::Medium) => Some("Binary(BlobSize::Medium)".into()),
|
||||
ColumnType::Binary(BlobSize::Long) => Some("Binary(BlobSize::Long)".into()),
|
||||
ColumnType::VarBinary(s) => Some(format!("VarBinary({s})")),
|
||||
ColumnType::Binary(s) => Some(format!("Binary({s})")),
|
||||
ColumnType::VarBinary(s) => match s {
|
||||
StringLen::N(s) => Some(format!("VarBinary(StringLen::N({s}))")),
|
||||
StringLen::None => Some("VarBinary(StringLen::None)".to_owned()),
|
||||
StringLen::Max => Some("VarBinary(StringLen::Max)".to_owned()),
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
col_type.map(|ty| quote! { column_type = #ty })
|
||||
@ -117,8 +115,9 @@ impl Column {
|
||||
None => quote! { ColumnType::Char(None) },
|
||||
},
|
||||
ColumnType::String(s) => match s {
|
||||
Some(s) => quote! { ColumnType::String(Some(#s)) },
|
||||
None => quote! { ColumnType::String(None) },
|
||||
StringLen::N(s) => quote! { ColumnType::string(Some(#s)) },
|
||||
StringLen::None => quote! { ColumnType::string(None) },
|
||||
StringLen::Max => quote! { ColumnType::String(StringLen::Max) },
|
||||
},
|
||||
ColumnType::Text => quote! { ColumnType::Text },
|
||||
ColumnType::TinyInteger => quote! { ColumnType::TinyInteger },
|
||||
@ -142,24 +141,14 @@ impl Column {
|
||||
}
|
||||
ColumnType::Time => quote! { ColumnType::Time },
|
||||
ColumnType::Date => quote! { ColumnType::Date },
|
||||
ColumnType::Binary(BlobSize::Blob(None)) => {
|
||||
quote! { ColumnType::Binary(BlobSize::Blob(None)) }
|
||||
}
|
||||
ColumnType::Binary(BlobSize::Blob(Some(s))) => {
|
||||
quote! { ColumnType::Binary(BlobSize::Blob(Some(#s))) }
|
||||
}
|
||||
ColumnType::Binary(BlobSize::Tiny) => {
|
||||
quote! { ColumnType::Binary(BlobSize::Tiny) }
|
||||
}
|
||||
ColumnType::Binary(BlobSize::Medium) => {
|
||||
quote! { ColumnType::Binary(BlobSize::Medium) }
|
||||
}
|
||||
ColumnType::Binary(BlobSize::Long) => {
|
||||
quote! { ColumnType::Binary(BlobSize::Long) }
|
||||
}
|
||||
ColumnType::VarBinary(s) => {
|
||||
quote! { ColumnType::VarBinary(#s) }
|
||||
ColumnType::Binary(s) => {
|
||||
quote! { ColumnType::Binary(#s) }
|
||||
}
|
||||
ColumnType::VarBinary(s) => match s {
|
||||
StringLen::N(s) => quote! { ColumnType::VarBinary(StringLen::N(#s)) },
|
||||
StringLen::None => quote! { ColumnType::VarBinary(StringLen::None) },
|
||||
StringLen::Max => quote! { ColumnType::VarBinary(StringLen::Max) },
|
||||
},
|
||||
ColumnType::Boolean => quote! { ColumnType::Boolean },
|
||||
ColumnType::Money(s) => match s {
|
||||
Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))) },
|
||||
@ -298,7 +287,7 @@ mod tests {
|
||||
use crate::{Column, DateTimeCrate};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use sea_query::{Alias, BlobSize, ColumnDef, ColumnType, SeaRc};
|
||||
use sea_query::{Alias, ColumnDef, ColumnType, SeaRc, StringLen};
|
||||
|
||||
fn setup() -> Vec<Column> {
|
||||
macro_rules! make_col {
|
||||
@ -313,7 +302,8 @@ mod tests {
|
||||
};
|
||||
}
|
||||
vec![
|
||||
make_col!("id", ColumnType::String(Some(255))),
|
||||
make_col!("id", ColumnType::string(Some(255))),
|
||||
make_col!("id", ColumnType::string(None)),
|
||||
make_col!(
|
||||
"cake_id",
|
||||
ColumnType::Custom(SeaRc::new(Alias::new("cus_col")))
|
||||
@ -328,15 +318,10 @@ mod tests {
|
||||
make_col!("CakeFillingId", ColumnType::BigUnsigned),
|
||||
make_col!("cake-filling-id", ColumnType::Float),
|
||||
make_col!("CAKE_FILLING_ID", ColumnType::Double),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Blob(None))),
|
||||
make_col!(
|
||||
"CAKE-FILLING-ID",
|
||||
ColumnType::Binary(BlobSize::Blob(Some(10)))
|
||||
),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Tiny)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Medium)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Long)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(10)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::Binary(10)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::None)),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::N(10))),
|
||||
make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::Max)),
|
||||
make_col!("CAKE", ColumnType::Boolean),
|
||||
make_col!("date", ColumnType::Date),
|
||||
make_col!("time", ColumnType::Time),
|
||||
@ -350,6 +335,7 @@ mod tests {
|
||||
fn test_get_name_snake_case() {
|
||||
let columns = setup();
|
||||
let snack_cases = vec![
|
||||
"id",
|
||||
"id",
|
||||
"cake_id",
|
||||
"cake_id",
|
||||
@ -366,8 +352,6 @@ mod tests {
|
||||
"cake_filling_id",
|
||||
"cake_filling_id",
|
||||
"cake_filling_id",
|
||||
"cake_filling_id",
|
||||
"cake_filling_id",
|
||||
"cake",
|
||||
"date",
|
||||
"time",
|
||||
@ -384,6 +368,7 @@ mod tests {
|
||||
fn test_get_name_camel_case() {
|
||||
let columns = setup();
|
||||
let camel_cases = vec![
|
||||
"Id",
|
||||
"Id",
|
||||
"CakeId",
|
||||
"CakeId",
|
||||
@ -400,8 +385,6 @@ mod tests {
|
||||
"CakeFillingId",
|
||||
"CakeFillingId",
|
||||
"CakeFillingId",
|
||||
"CakeFillingId",
|
||||
"CakeFillingId",
|
||||
"Cake",
|
||||
"Date",
|
||||
"Time",
|
||||
@ -419,6 +402,7 @@ mod tests {
|
||||
let columns = setup();
|
||||
let chrono_crate = DateTimeCrate::Chrono;
|
||||
let rs_types = vec![
|
||||
"String",
|
||||
"String",
|
||||
"String",
|
||||
"i8",
|
||||
@ -435,8 +419,6 @@ mod tests {
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"bool",
|
||||
"Date",
|
||||
"Time",
|
||||
@ -466,6 +448,7 @@ mod tests {
|
||||
let columns = setup();
|
||||
let time_crate = DateTimeCrate::Time;
|
||||
let rs_types = vec![
|
||||
"String",
|
||||
"String",
|
||||
"String",
|
||||
"i8",
|
||||
@ -482,8 +465,6 @@ mod tests {
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"Vec<u8>",
|
||||
"bool",
|
||||
"TimeDate",
|
||||
"TimeTime",
|
||||
@ -512,7 +493,8 @@ mod tests {
|
||||
fn test_get_def() {
|
||||
let columns = setup();
|
||||
let col_defs = vec![
|
||||
"ColumnType::String(Some(255u32)).def()",
|
||||
"ColumnType::string(Some(255u32)).def()",
|
||||
"ColumnType::string(None).def()",
|
||||
"ColumnType::custom(\"cus_col\").def()",
|
||||
"ColumnType::TinyInteger.def()",
|
||||
"ColumnType::TinyUnsigned.def()",
|
||||
@ -524,12 +506,10 @@ mod tests {
|
||||
"ColumnType::BigUnsigned.def()",
|
||||
"ColumnType::Float.def()",
|
||||
"ColumnType::Double.def()",
|
||||
"ColumnType::Binary(BlobSize::Blob(None)).def()",
|
||||
"ColumnType::Binary(BlobSize::Blob(Some(10u32))).def()",
|
||||
"ColumnType::Binary(BlobSize::Tiny).def()",
|
||||
"ColumnType::Binary(BlobSize::Medium).def()",
|
||||
"ColumnType::Binary(BlobSize::Long).def()",
|
||||
"ColumnType::VarBinary(10u32).def()",
|
||||
"ColumnType::Binary(10u32).def()",
|
||||
"ColumnType::VarBinary(StringLen::None).def()",
|
||||
"ColumnType::VarBinary(StringLen::N(10u32)).def()",
|
||||
"ColumnType::VarBinary(StringLen::Max).def()",
|
||||
"ColumnType::Boolean.def()",
|
||||
"ColumnType::Date.def()",
|
||||
"ColumnType::Time.def()",
|
||||
@ -701,7 +681,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
column.get_def().to_string(),
|
||||
quote! {
|
||||
ColumnType::String(None).def().null()
|
||||
ColumnType::string(None).def().null()
|
||||
}
|
||||
.to_string()
|
||||
);
|
||||
|
@ -993,7 +993,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "name".to_owned(),
|
||||
col_type: ColumnType::String(Some(255)),
|
||||
col_type: ColumnType::string(Some(255)),
|
||||
auto_increment: false,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
@ -1020,7 +1020,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "name".to_owned(),
|
||||
col_type: ColumnType::String(Some(255)),
|
||||
col_type: ColumnType::string(Some(255)),
|
||||
auto_increment: false,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
@ -1074,7 +1074,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "_name_".to_owned(),
|
||||
col_type: ColumnType::String(Some(255)),
|
||||
col_type: ColumnType::string(Some(255)),
|
||||
auto_increment: false,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
|
@ -44,7 +44,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::string(Some(255u32)).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,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::string(Some(255u32)).def(),
|
||||
Self::CakeId => ColumnType::Integer.def().null(),
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,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::string(Some(255u32)).def(),
|
||||
Self::FruitId => ColumnType::Integer.def().null(),
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,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::string(Some(255u32)).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,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::string(Some(255u32)).def(),
|
||||
Self::CakeId => ColumnType::Integer.def().null(),
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,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::string(Some(255u32)).def(),
|
||||
Self::FruitId => ColumnType::Integer.def().null(),
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub fn col_type_match(
|
||||
None => {
|
||||
let col_type = match field_type {
|
||||
"char" => quote! { Char(None) },
|
||||
"String" | "&str" => quote! { String(None) },
|
||||
"String" | "&str" => quote! { string(None) },
|
||||
"i8" => quote! { TinyInteger },
|
||||
"u8" => quote! { TinyUnsigned },
|
||||
"i16" => quote! { SmallInteger },
|
||||
@ -36,7 +36,7 @@ pub fn col_type_match(
|
||||
"Json" => quote! { Json },
|
||||
"Decimal" => quote! { Decimal(None) },
|
||||
"Vec<u8>" => {
|
||||
quote! { Binary(sea_orm::sea_query::BlobSize::Blob(None)) }
|
||||
quote! { VarBinary(sea_orm::sea_query::StringLen::None) }
|
||||
}
|
||||
_ => {
|
||||
// Assumed it's ActiveEnum if none of the above type matches
|
||||
|
@ -60,7 +60,7 @@ mod strum;
|
||||
/// # fn def(&self) -> ColumnDef {
|
||||
/// # match self {
|
||||
/// # Self::Id => ColumnType::Integer.def(),
|
||||
/// # Self::Name => ColumnType::String(None).def(),
|
||||
/// # Self::Name => ColumnType::string(None).def(),
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
@ -344,7 +344,7 @@ pub fn derive_custom_column(input: TokenStream) -> TokenStream {
|
||||
/// # fn def(&self) -> ColumnDef {
|
||||
/// # match self {
|
||||
/// # Self::Id => ColumnType::Integer.def(),
|
||||
/// # Self::Name => ColumnType::String(None).def(),
|
||||
/// # Self::Name => ColumnType::string(None).def(),
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
@ -417,7 +417,7 @@ pub fn derive_model(input: TokenStream) -> TokenStream {
|
||||
/// # fn def(&self) -> ColumnDef {
|
||||
/// # match self {
|
||||
/// # Self::Id => ColumnType::Integer.def(),
|
||||
/// # Self::Name => ColumnType::String(None).def(),
|
||||
/// # Self::Name => ColumnType::string(None).def(),
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
@ -503,7 +503,7 @@ pub fn derive_into_active_model(input: TokenStream) -> TokenStream {
|
||||
/// # fn def(&self) -> ColumnDef {
|
||||
/// # match self {
|
||||
/// # Self::Id => ColumnType::Integer.def(),
|
||||
/// # Self::Name => ColumnType::String(None).def(),
|
||||
/// # Self::Name => ColumnType::string(None).def(),
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
|
@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
||||
dotenvy = { version = "0.15", default-features = false, optional = true }
|
||||
sea-orm = { version = "0.12.12", path = "../", default-features = false, features = ["macros"] }
|
||||
sea-orm-cli = { version = "0.12.12", path = "../sea-orm-cli", default-features = false, optional = true }
|
||||
sea-schema = { version = "0.14.1" }
|
||||
sea-schema = { version = "0.15.0-rc.1" }
|
||||
tracing = { version = "0.1", default-features = false, features = ["log"] }
|
||||
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
|
||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||
|
@ -20,7 +20,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType};
|
||||
/// #[derive(Debug, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
/// #[sea_orm(
|
||||
/// rs_type = "String",
|
||||
/// db_type = "String(Some(1))",
|
||||
/// db_type = "string(Some(1))",
|
||||
/// enum_name = "category"
|
||||
/// )]
|
||||
/// pub enum DeriveCategory {
|
||||
@ -74,7 +74,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType};
|
||||
///
|
||||
/// fn db_type() -> ColumnDef {
|
||||
/// // The macro attribute `db_type` is being pasted here
|
||||
/// ColumnType::String(Some(1)).def()
|
||||
/// ColumnType::string(Some(1)).def()
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@ -86,7 +86,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType};
|
||||
///
|
||||
/// // Define the `Category` active enum
|
||||
/// #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
/// #[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
|
||||
/// #[sea_orm(rs_type = "String", db_type = "string(Some(1))")]
|
||||
/// pub enum Category {
|
||||
/// #[sea_orm(string_value = "B")]
|
||||
/// Big,
|
||||
@ -246,14 +246,14 @@ mod tests {
|
||||
}
|
||||
|
||||
fn db_type() -> ColumnDef {
|
||||
ColumnType::String(Some(1)).def()
|
||||
ColumnType::string(Some(1)).def()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "String(Some(1))",
|
||||
db_type = "string(Some(1))",
|
||||
enum_name = "category"
|
||||
)]
|
||||
pub enum DeriveCategory {
|
||||
@ -293,8 +293,8 @@ mod tests {
|
||||
Some(DeriveCategory::Small)
|
||||
);
|
||||
|
||||
assert_eq!(Category::db_type(), ColumnType::String(Some(1)).def());
|
||||
assert_eq!(DeriveCategory::db_type(), ColumnType::String(Some(1)).def());
|
||||
assert_eq!(Category::db_type(), ColumnType::string(Some(1)).def());
|
||||
assert_eq!(DeriveCategory::db_type(), ColumnType::string(Some(1)).def());
|
||||
|
||||
assert_eq!(
|
||||
Category::name().to_string(),
|
||||
@ -496,7 +496,7 @@ mod tests {
|
||||
#[derive(Clone, Debug, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "String(None)",
|
||||
db_type = "string(None)",
|
||||
enum_name = "conflicting_string_values"
|
||||
)]
|
||||
pub enum ConflictingStringValues {
|
||||
|
@ -620,11 +620,11 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
hello::Column::Twelve.def(),
|
||||
ColumnType::String(None).def().default("twelve_value")
|
||||
ColumnType::string(None).def().default("twelve_value")
|
||||
);
|
||||
assert_eq!(
|
||||
hello::Column::TwelveTwo.def(),
|
||||
ColumnType::String(None).def().default("twelve_value")
|
||||
ColumnType::string(None).def().default("twelve_value")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
||||
/// fn def(&self) -> ColumnDef {
|
||||
/// match self {
|
||||
/// Self::Id => ColumnType::Integer.def(),
|
||||
/// Self::Name => ColumnType::String(None).def(),
|
||||
/// Self::Name => ColumnType::string(None).def(),
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use crate::{
|
||||
error::*,
|
||||
sea_query::{BlobSize, DynIden, Expr, RcOrArc, SeaRc},
|
||||
sea_query::{DynIden, Expr, RcOrArc, SeaRc, StringLen},
|
||||
ActiveEnum, ActiveModelBehavior, ActiveModelTrait, ColumnDef, ColumnTrait, ColumnType,
|
||||
ColumnTypeTrait, ConnectionTrait, CursorTrait, DatabaseConnection, DbConn, EntityName,
|
||||
EntityTrait, EnumIter, ForeignKeyAction, Iden, IdenStatic, Linked, LoaderTrait, ModelTrait,
|
||||
|
@ -170,7 +170,7 @@ mod tests {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "String(Some(1))",
|
||||
db_type = "string(Some(1))",
|
||||
enum_name = "category"
|
||||
)]
|
||||
pub enum DeriveCategory {
|
||||
|
@ -197,13 +197,16 @@ where
|
||||
{
|
||||
let orm_column_def = column.def();
|
||||
let types = match orm_column_def.col_type {
|
||||
ColumnType::Enum { name, variants } => match backend {
|
||||
ColumnType::Enum {
|
||||
ref name,
|
||||
ref variants,
|
||||
} => match backend {
|
||||
DbBackend::MySql => {
|
||||
let variants: Vec<String> = variants.iter().map(|v| v.to_string()).collect();
|
||||
ColumnType::custom(format!("ENUM('{}')", variants.join("', '")).as_str())
|
||||
}
|
||||
DbBackend::Postgres => ColumnType::Custom(SeaRc::clone(&name)),
|
||||
DbBackend::Sqlite => ColumnType::Text,
|
||||
DbBackend::Postgres => ColumnType::Custom(SeaRc::clone(name)),
|
||||
DbBackend::Sqlite => orm_column_def.col_type,
|
||||
},
|
||||
_ => orm_column_def.col_type,
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
Self::VendorId => ColumnType::Integer.def().nullable(),
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
Self::Tea => Tea::db_type().def(),
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
#[sea_orm(column_type = "Decimal(Some((19, 4)))")]
|
||||
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
|
||||
pub price: Decimal,
|
||||
pub bakery_id: Option<i32>,
|
||||
pub gluten_free: bool,
|
||||
|
@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(column_type = "Decimal(Some((19, 4)))")]
|
||||
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
|
||||
pub price: Decimal,
|
||||
pub quantity: i32,
|
||||
pub order_id: i32,
|
||||
|
@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(column_type = "Decimal(Some((19, 4)))")]
|
||||
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
|
||||
pub total: Decimal,
|
||||
pub bakery_id: i32,
|
||||
pub customer_id: i32,
|
||||
|
@ -95,7 +95,7 @@ pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(order::Column::Total)
|
||||
.decimal_len(19, 4)
|
||||
.decimal_len(16, 4)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(order::Column::BakeryId).integer().not_null())
|
||||
@ -142,7 +142,7 @@ pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(lineitem::Column::Price)
|
||||
.decimal_len(19, 4)
|
||||
.decimal_len(16, 4)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
@ -234,7 +234,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.col(ColumnDef::new(cake::Column::Name).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(cake::Column::Price)
|
||||
.decimal_len(19, 4)
|
||||
.decimal_len(16, 4)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(cake::Column::BakeryId).integer())
|
||||
|
@ -5,18 +5,12 @@ use sea_orm::entity::prelude::*;
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
|
||||
#[sea_orm(column_type = "Binary(1)")]
|
||||
pub binary: Vec<u8>,
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Blob(Some(10)))")]
|
||||
#[sea_orm(column_type = "Binary(10)")]
|
||||
pub binary_10: Vec<u8>,
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Tiny)")]
|
||||
pub binary_tiny: Vec<u8>,
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Medium)")]
|
||||
pub binary_medium: Vec<u8>,
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Long)")]
|
||||
pub binary_long: Vec<u8>,
|
||||
#[sea_orm(column_type = "VarBinary(10)")]
|
||||
pub var_binary: Vec<u8>,
|
||||
#[sea_orm(column_type = "VarBinary(StringLen::N(16))")]
|
||||
pub var_binary_16: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
@ -48,7 +48,7 @@ impl ColumnTrait for Column {
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Name => ColumnType::String(None).def(),
|
||||
Self::Name => ColumnType::string(None).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,6 @@ impl ValueType for Events {
|
||||
}
|
||||
|
||||
fn column_type() -> ColumnType {
|
||||
ColumnType::Array(RcOrArc::new(ColumnType::String(None)))
|
||||
ColumnType::Array(RcOrArc::new(ColumnType::string(None)))
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ pub struct Model {
|
||||
pub ty: String,
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
#[sea_orm(column_type = "var_binary(32)")]
|
||||
pub bytes: Vec<u8>,
|
||||
pub date: Option<Date>,
|
||||
pub time: Option<Time>,
|
||||
|
@ -5,8 +5,8 @@ use sea_orm::{
|
||||
ExecResult, Schema,
|
||||
};
|
||||
use sea_query::{
|
||||
extension::postgres::Type, Alias, BlobSize, ColumnDef, ColumnType, ForeignKeyCreateStatement,
|
||||
IntoIden,
|
||||
extension::postgres::Type, Alias, ColumnDef, ColumnType, ForeignKeyCreateStatement, IntoIden,
|
||||
StringLen,
|
||||
};
|
||||
|
||||
pub async fn create_tables(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
@ -111,7 +111,13 @@ pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.col(ColumnDef::new(metadata::Column::Type).string().not_null())
|
||||
.col(ColumnDef::new(metadata::Column::Key).string().not_null())
|
||||
.col(ColumnDef::new(metadata::Column::Value).string().not_null())
|
||||
.col(ColumnDef::new(metadata::Column::Bytes).binary().not_null())
|
||||
.col(
|
||||
ColumnDef::new_with_type(
|
||||
metadata::Column::Bytes,
|
||||
ColumnType::VarBinary(StringLen::N(32)),
|
||||
)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(metadata::Column::Date).date())
|
||||
.col(ColumnDef::new(metadata::Column::Time).time())
|
||||
.to_owned();
|
||||
@ -502,7 +508,7 @@ pub async fn create_event_trigger_table(db: &DbConn) -> Result<ExecResult, DbErr
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(event_trigger::Column::Events)
|
||||
.array(sea_query::ColumnType::String(None))
|
||||
.array(sea_query::ColumnType::string(None))
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned();
|
||||
@ -584,7 +590,7 @@ pub async fn create_categories_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(categories::Column::Categories).array(ColumnType::String(Some(1))))
|
||||
.col(ColumnDef::new(categories::Column::Categories).array(ColumnType::string(Some(1))))
|
||||
.to_owned();
|
||||
|
||||
create_table(db, &create_table_stmt, Categories).await
|
||||
@ -603,27 +609,12 @@ pub async fn create_binary_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.col(ColumnDef::new(binary::Column::Binary).binary().not_null())
|
||||
.col(
|
||||
ColumnDef::new(binary::Column::Binary10)
|
||||
.blob(BlobSize::Blob(Some(10)))
|
||||
.binary_len(10)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(binary::Column::BinaryTiny)
|
||||
.blob(BlobSize::Tiny)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(binary::Column::BinaryMedium)
|
||||
.blob(BlobSize::Medium)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(binary::Column::BinaryLong)
|
||||
.blob(BlobSize::Long)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(binary::Column::VarBinary)
|
||||
.var_binary(10)
|
||||
ColumnDef::new(binary::Column::VarBinary16)
|
||||
.var_binary(16)
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned();
|
||||
@ -742,7 +733,7 @@ pub async fn create_value_type_postgres_table(db: &DbConn) -> Result<ExecResult,
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(json_vec::Column::StrVec)
|
||||
.array(sea_query::ColumnType::String(None))
|
||||
.array(sea_query::ColumnType::string(None))
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned();
|
||||
|
@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
|
||||
#[sea_orm(rs_type = "String", db_type = "string(Some(1))")]
|
||||
pub enum Category {
|
||||
#[sea_orm(string_value = "B")]
|
||||
Big,
|
||||
|
@ -38,9 +38,11 @@ pub async fn test_update_cake(db: &DbConn) {
|
||||
assert_eq!(cake_model.price, rust_dec(10.25));
|
||||
assert!(!cake_model.gluten_free);
|
||||
|
||||
let large_number = "1234_5678_9012.3456".parse().unwrap();
|
||||
|
||||
let mut cake_am: cake::ActiveModel = cake_model.into();
|
||||
cake_am.name = Set("Extra chocolate mud cake".to_owned());
|
||||
cake_am.price = Set(rust_dec(20.00));
|
||||
cake_am.price = Set(large_number);
|
||||
|
||||
let _cake_update_res: cake::Model = cake_am.update(db).await.expect("could not update cake");
|
||||
|
||||
@ -50,7 +52,7 @@ pub async fn test_update_cake(db: &DbConn) {
|
||||
.expect("could not find cake");
|
||||
let cake_model = cake.unwrap();
|
||||
assert_eq!(cake_model.name, "Extra chocolate mud cake");
|
||||
assert_eq!(cake_model.price, rust_dec(20.00));
|
||||
assert_eq!(cake_model.price, large_number);
|
||||
assert!(!cake_model.gluten_free);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ pub fn type_test() {
|
||||
// self implied
|
||||
assert_eq!(
|
||||
StringVec::column_type(),
|
||||
ColumnType::Array(Arc::new(ColumnType::String(None)))
|
||||
ColumnType::Array(Arc::new(ColumnType::string(None)))
|
||||
);
|
||||
assert_eq!(StringVec::array_type(), ArrayType::String);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user