Explicit StringLen
on ColumnType::String
(#2123)
This commit is contained in:
parent
9318a544fc
commit
b775027fee
@ -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(StringLen::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(StringLen::None).def(),
|
||||
Self::CakeId => ColumnType::Integer.def(),
|
||||
}
|
||||
}
|
||||
|
@ -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(StringLen::N(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(StringLen::None).def(),
|
||||
Self::VendorId => ColumnType::Integer.def().nullable(),
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ impl Entity {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use quote::{format_ident, quote};
|
||||
use sea_query::{ColumnType, ForeignKeyAction};
|
||||
use sea_query::{ColumnType, ForeignKeyAction, StringLen};
|
||||
|
||||
use crate::{Column, DateTimeCrate, Entity, PrimaryKey, Relation, RelationType};
|
||||
|
||||
@ -284,7 +284,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "name".to_owned(),
|
||||
col_type: ColumnType::string(None),
|
||||
col_type: ColumnType::String(StringLen::None),
|
||||
auto_increment: false,
|
||||
not_null: false,
|
||||
unique: false,
|
||||
|
@ -115,8 +115,8 @@ impl Column {
|
||||
None => quote! { ColumnType::Char(None) },
|
||||
},
|
||||
ColumnType::String(s) => match s {
|
||||
StringLen::N(s) => quote! { ColumnType::string(Some(#s)) },
|
||||
StringLen::None => quote! { ColumnType::string(None) },
|
||||
StringLen::N(s) => quote! { ColumnType::String(StringLen::N(#s)) },
|
||||
StringLen::None => quote! { ColumnType::String(StringLen::None) },
|
||||
StringLen::Max => quote! { ColumnType::String(StringLen::Max) },
|
||||
},
|
||||
ColumnType::Text => quote! { ColumnType::Text },
|
||||
@ -302,8 +302,8 @@ mod tests {
|
||||
};
|
||||
}
|
||||
vec![
|
||||
make_col!("id", ColumnType::string(Some(255))),
|
||||
make_col!("id", ColumnType::string(None)),
|
||||
make_col!("id", ColumnType::String(StringLen::N(255))),
|
||||
make_col!("id", ColumnType::String(StringLen::None)),
|
||||
make_col!(
|
||||
"cake_id",
|
||||
ColumnType::Custom(SeaRc::new(Alias::new("cus_col")))
|
||||
@ -493,8 +493,8 @@ mod tests {
|
||||
fn test_get_def() {
|
||||
let columns = setup();
|
||||
let col_defs = vec![
|
||||
"ColumnType::string(Some(255u32)).def()",
|
||||
"ColumnType::string(None).def()",
|
||||
"ColumnType::String(StringLen::N(255u32)).def()",
|
||||
"ColumnType::String(StringLen::None).def()",
|
||||
"ColumnType::custom(\"cus_col\").def()",
|
||||
"ColumnType::TinyInteger.def()",
|
||||
"ColumnType::TinyUnsigned.def()",
|
||||
@ -681,7 +681,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
column.get_def().to_string(),
|
||||
quote! {
|
||||
ColumnType::string(None).def().null()
|
||||
ColumnType::String(StringLen::None).def().null()
|
||||
}
|
||||
.to_string()
|
||||
);
|
||||
|
@ -841,7 +841,7 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use sea_query::{Alias, ColumnType, ForeignKeyAction, RcOrArc, SeaRc};
|
||||
use sea_query::{Alias, ColumnType, ForeignKeyAction, RcOrArc, SeaRc, StringLen};
|
||||
use std::io::{self, BufRead, BufReader, Read};
|
||||
|
||||
fn setup() -> Vec<Entity> {
|
||||
@ -993,7 +993,7 @@ mod tests {
|
||||
},
|
||||
Column {
|
||||
name: "name".to_owned(),
|
||||
col_type: ColumnType::string(Some(255)),
|
||||
col_type: ColumnType::String(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(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(StringLen::N(255u32)).def(),
|
||||
Self::FruitId => ColumnType::Integer.def().null(),
|
||||
}
|
||||
}
|
||||
|
@ -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(StringLen::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(StringLen::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(StringLen::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(StringLen::None).def(),
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
|
@ -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(StringLen::N(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(StringLen::N(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(StringLen::N(1))")]
|
||||
/// pub enum Category {
|
||||
/// #[sea_orm(string_value = "B")]
|
||||
/// Big,
|
||||
@ -205,7 +205,11 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate as sea_orm;
|
||||
use crate::{error::*, sea_query::SeaRc, *};
|
||||
use crate::{
|
||||
error::*,
|
||||
sea_query::{SeaRc, StringLen},
|
||||
*,
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
@ -246,14 +250,14 @@ mod tests {
|
||||
}
|
||||
|
||||
fn db_type() -> ColumnDef {
|
||||
ColumnType::string(Some(1)).def()
|
||||
ColumnType::String(StringLen::N(1)).def()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "string(Some(1))",
|
||||
db_type = "String(StringLen::N(1))",
|
||||
enum_name = "category"
|
||||
)]
|
||||
pub enum DeriveCategory {
|
||||
@ -293,8 +297,14 @@ 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(StringLen::N(1)).def()
|
||||
);
|
||||
assert_eq!(
|
||||
DeriveCategory::db_type(),
|
||||
ColumnType::String(StringLen::N(1)).def()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Category::name().to_string(),
|
||||
@ -496,7 +506,7 @@ mod tests {
|
||||
#[derive(Clone, Debug, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "string(None)",
|
||||
db_type = "String(StringLen::None)",
|
||||
enum_name = "conflicting_string_values"
|
||||
)]
|
||||
pub enum ConflictingStringValues {
|
||||
|
@ -620,11 +620,15 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
hello::Column::Twelve.def(),
|
||||
ColumnType::string(None).def().default("twelve_value")
|
||||
ColumnType::String(StringLen::None)
|
||||
.def()
|
||||
.default("twelve_value")
|
||||
);
|
||||
assert_eq!(
|
||||
hello::Column::TwelveTwo.def(),
|
||||
ColumnType::string(None).def().default("twelve_value")
|
||||
ColumnType::String(StringLen::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(StringLen::None).def(),
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -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(StringLen::N(1))",
|
||||
enum_name = "category"
|
||||
)]
|
||||
pub enum DeriveCategory {
|
||||
|
@ -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(StringLen::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(StringLen::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(StringLen::None).def(),
|
||||
Self::Tea => Tea::db_type().def(),
|
||||
}
|
||||
}
|
||||
|
@ -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(StringLen::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(StringLen::None)))
|
||||
}
|
||||
}
|
||||
|
@ -508,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(StringLen::None))
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned();
|
||||
@ -590,7 +590,10 @@ 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(StringLen::N(1))),
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
create_table(db, &create_table_stmt, Categories).await
|
||||
@ -733,7 +736,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(StringLen::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(StringLen::N(1))")]
|
||||
pub enum Category {
|
||||
#[sea_orm(string_value = "B")]
|
||||
Big,
|
||||
|
@ -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(StringLen::None)))
|
||||
);
|
||||
assert_eq!(StringVec::array_type(), ArrayType::String);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user