Column type can be Uuid
This commit is contained in:
parent
47b70cfe6d
commit
c9833893c0
13
Cargo.toml
13
Cargo.toml
@ -43,21 +43,25 @@ futures = { version = "^0.3" }
|
|||||||
futures-util = { version = "^0.3" }
|
futures-util = { version = "^0.3" }
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-query = { version = "^0.12" }
|
sea-query = { version = "^0.12" }
|
||||||
|
# sea-query = { path = "../sea-query" }
|
||||||
sea-orm-macros = { path = "sea-orm-macros", optional = true }
|
sea-orm-macros = { path = "sea-orm-macros", optional = true }
|
||||||
sea-orm-codegen = { path = "sea-orm-codegen", optional = true }
|
sea-orm-codegen = { path = "sea-orm-codegen", optional = true }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
sqlx = { version = "^0.5", optional = true }
|
sqlx = { version = "^0.5", optional = true }
|
||||||
|
sqlx-core = { version = "^0.5", optional = true }
|
||||||
|
sqlx-macros = { version = "^0.5", optional = true }
|
||||||
strum = { git = "https://github.com/SeaQL/strum.git", branch = "sea-orm", version = "^0.21", features = [
|
strum = { git = "https://github.com/SeaQL/strum.git", branch = "sea-orm", version = "^0.21", features = [
|
||||||
"derive",
|
"derive",
|
||||||
"sea-orm",
|
"sea-orm",
|
||||||
] }
|
] }
|
||||||
serde_json = { version = "^1", optional = true }
|
serde_json = { version = "^1", optional = true }
|
||||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
uuid = { version = "0.8", features = ["serde", "v4"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "^1.9", features = ["attributes"] }
|
async-std = { version = "^1.9", features = ["attributes"] }
|
||||||
maplit = { version = "^1" }
|
maplit = { version = "^1" }
|
||||||
rust_decimal_macros = { version = "^1" }
|
rust_decimal_macros = { version = "^1" }
|
||||||
|
|
||||||
sea-orm = { path = ".", features = [
|
sea-orm = { path = ".", features = [
|
||||||
"sqlx-sqlite",
|
"sqlx-sqlite",
|
||||||
"sqlx-json",
|
"sqlx-json",
|
||||||
@ -76,6 +80,7 @@ default = [
|
|||||||
"with-chrono",
|
"with-chrono",
|
||||||
"with-rust_decimal",
|
"with-rust_decimal",
|
||||||
"mock",
|
"mock",
|
||||||
|
"with-uuid",
|
||||||
]
|
]
|
||||||
macros = ["sea-orm-macros"]
|
macros = ["sea-orm-macros"]
|
||||||
codegen = ["sea-orm-codegen"]
|
codegen = ["sea-orm-codegen"]
|
||||||
@ -83,6 +88,12 @@ mock = []
|
|||||||
with-json = ["serde_json", "sea-query/with-json"]
|
with-json = ["serde_json", "sea-query/with-json"]
|
||||||
with-chrono = ["chrono", "sea-query/with-chrono"]
|
with-chrono = ["chrono", "sea-query/with-chrono"]
|
||||||
with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal"]
|
with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal"]
|
||||||
|
with-uuid = [
|
||||||
|
"uuid",
|
||||||
|
"sea-query/with-uuid",
|
||||||
|
"sqlx-core/uuid",
|
||||||
|
"sqlx-macros/uuid",
|
||||||
|
]
|
||||||
sqlx-dep = ["sqlx"]
|
sqlx-dep = ["sqlx"]
|
||||||
sqlx-json = ["sqlx/json", "with-json"]
|
sqlx-json = ["sqlx/json", "with-json"]
|
||||||
sqlx-chrono = ["sqlx/chrono", "with-chrono"]
|
sqlx-chrono = ["sqlx/chrono", "with-chrono"]
|
||||||
|
@ -31,6 +31,7 @@ pub enum ColumnType {
|
|||||||
Json,
|
Json,
|
||||||
JsonBinary,
|
JsonBinary,
|
||||||
Custom(String),
|
Custom(String),
|
||||||
|
Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! bind_oper {
|
macro_rules! bind_oper {
|
||||||
@ -270,6 +271,7 @@ impl From<ColumnType> for sea_query::ColumnType {
|
|||||||
ColumnType::Custom(s) => {
|
ColumnType::Custom(s) => {
|
||||||
sea_query::ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(&s)))
|
sea_query::ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(&s)))
|
||||||
}
|
}
|
||||||
|
ColumnType::Uuid => sea_query::ColumnType::Uuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,6 +299,7 @@ impl From<sea_query::ColumnType> for ColumnType {
|
|||||||
sea_query::ColumnType::Json => Self::Json,
|
sea_query::ColumnType::Json => Self::Json,
|
||||||
sea_query::ColumnType::JsonBinary => Self::JsonBinary,
|
sea_query::ColumnType::JsonBinary => Self::JsonBinary,
|
||||||
sea_query::ColumnType::Custom(s) => Self::Custom(s.to_string()),
|
sea_query::ColumnType::Custom(s) => Self::Custom(s.to_string()),
|
||||||
|
sea_query::ColumnType::Uuid => Self::Uuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,12 @@ try_getable_all!(f64);
|
|||||||
try_getable_all!(String);
|
try_getable_all!(String);
|
||||||
try_getable_all!(NaiveDateTime);
|
try_getable_all!(NaiveDateTime);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-uuid")]
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[cfg(feature = "with-uuid")]
|
||||||
|
try_getable_all!(Uuid);
|
||||||
|
|
||||||
#[cfg(feature = "with-rust_decimal")]
|
#[cfg(feature = "with-rust_decimal")]
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use rust_decimal::prelude::*;
|
use rust_decimal::prelude::*;
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||||
pub struct Entity;
|
pub struct Entity;
|
||||||
@ -17,7 +18,7 @@ pub struct Model {
|
|||||||
pub price: Decimal,
|
pub price: Decimal,
|
||||||
pub bakery_id: Option<i32>,
|
pub bakery_id: Option<i32>,
|
||||||
pub gluten_free: bool,
|
pub gluten_free: bool,
|
||||||
pub serial: String,
|
pub serial: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
@ -205,7 +205,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
.on_update(ForeignKeyAction::Cascade),
|
.on_update(ForeignKeyAction::Cascade),
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(cake::Column::GlutenFree).boolean())
|
.col(ColumnDef::new(cake::Column::GlutenFree).boolean())
|
||||||
.col(ColumnDef::new(cake::Column::Serial).string())
|
.col(ColumnDef::new(cake::Column::Serial).uuid())
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
create_table(db, &stmt).await
|
create_table(db, &stmt).await
|
||||||
|
@ -28,7 +28,7 @@ pub async fn test_create_cake(db: &DbConn) {
|
|||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
gluten_free: Set(false),
|
gluten_free: Set(false),
|
||||||
serial: Set(uuid.to_string()),
|
serial: Set(uuid),
|
||||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -68,7 +68,7 @@ pub async fn test_create_cake(db: &DbConn) {
|
|||||||
.name,
|
.name,
|
||||||
"SeaSide Bakery"
|
"SeaSide Bakery"
|
||||||
);
|
);
|
||||||
assert_eq!(cake_model.serial, uuid.to_string());
|
assert_eq!(cake_model.serial, uuid);
|
||||||
|
|
||||||
let related_bakers: Vec<baker::Model> = cake_model
|
let related_bakers: Vec<baker::Model> = cake_model
|
||||||
.find_related(Baker)
|
.find_related(Baker)
|
||||||
|
@ -31,7 +31,7 @@ pub async fn test_create_lineitem(db: &DbConn) {
|
|||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
gluten_free: Set(false),
|
gluten_free: Set(false),
|
||||||
serial: Set(Uuid::new_v4().to_string()),
|
serial: Set(Uuid::new_v4()),
|
||||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ pub async fn test_create_order(db: &DbConn) {
|
|||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
gluten_free: Set(false),
|
gluten_free: Set(false),
|
||||||
serial: Set(Uuid::new_v4().to_string()),
|
serial: Set(Uuid::new_v4()),
|
||||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ pub async fn test_delete_cake(db: &DbConn) {
|
|||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
gluten_free: Set(false),
|
gluten_free: Set(false),
|
||||||
serial: Set(Uuid::new_v4().to_string()),
|
serial: Set(Uuid::new_v4()),
|
||||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ pub async fn test_update_cake(db: &DbConn) {
|
|||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
gluten_free: Set(false),
|
gluten_free: Set(false),
|
||||||
serial: Set(Uuid::new_v4().to_string()),
|
serial: Set(Uuid::new_v4()),
|
||||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user