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" }
|
||||
rust_decimal = { version = "^1", optional = true }
|
||||
sea-query = { version = "^0.12" }
|
||||
# sea-query = { path = "../sea-query" }
|
||||
sea-orm-macros = { path = "sea-orm-macros", optional = true }
|
||||
sea-orm-codegen = { path = "sea-orm-codegen", optional = true }
|
||||
serde = { version = "^1.0", features = ["derive"] }
|
||||
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 = [
|
||||
"derive",
|
||||
"sea-orm",
|
||||
] }
|
||||
serde_json = { version = "^1", optional = true }
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
uuid = { version = "0.8", features = ["serde", "v4"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
async-std = { version = "^1.9", features = ["attributes"] }
|
||||
maplit = { version = "^1" }
|
||||
rust_decimal_macros = { version = "^1" }
|
||||
|
||||
sea-orm = { path = ".", features = [
|
||||
"sqlx-sqlite",
|
||||
"sqlx-json",
|
||||
@ -76,6 +80,7 @@ default = [
|
||||
"with-chrono",
|
||||
"with-rust_decimal",
|
||||
"mock",
|
||||
"with-uuid",
|
||||
]
|
||||
macros = ["sea-orm-macros"]
|
||||
codegen = ["sea-orm-codegen"]
|
||||
@ -83,6 +88,12 @@ mock = []
|
||||
with-json = ["serde_json", "sea-query/with-json"]
|
||||
with-chrono = ["chrono", "sea-query/with-chrono"]
|
||||
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-json = ["sqlx/json", "with-json"]
|
||||
sqlx-chrono = ["sqlx/chrono", "with-chrono"]
|
||||
|
@ -31,6 +31,7 @@ pub enum ColumnType {
|
||||
Json,
|
||||
JsonBinary,
|
||||
Custom(String),
|
||||
Uuid,
|
||||
}
|
||||
|
||||
macro_rules! bind_oper {
|
||||
@ -270,6 +271,7 @@ impl From<ColumnType> for sea_query::ColumnType {
|
||||
ColumnType::Custom(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::JsonBinary => Self::JsonBinary,
|
||||
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!(NaiveDateTime);
|
||||
|
||||
#[cfg(feature = "with-uuid")]
|
||||
use uuid::Uuid;
|
||||
|
||||
#[cfg(feature = "with-uuid")]
|
||||
try_getable_all!(Uuid);
|
||||
|
||||
#[cfg(feature = "with-rust_decimal")]
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
use rust_decimal::prelude::*;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
@ -17,7 +18,7 @@ pub struct Model {
|
||||
pub price: Decimal,
|
||||
pub bakery_id: Option<i32>,
|
||||
pub gluten_free: bool,
|
||||
pub serial: String,
|
||||
pub serial: Uuid,
|
||||
}
|
||||
|
||||
#[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),
|
||||
)
|
||||
.col(ColumnDef::new(cake::Column::GlutenFree).boolean())
|
||||
.col(ColumnDef::new(cake::Column::Serial).string())
|
||||
.col(ColumnDef::new(cake::Column::Serial).uuid())
|
||||
.to_owned();
|
||||
|
||||
create_table(db, &stmt).await
|
||||
|
@ -28,7 +28,7 @@ pub async fn test_create_cake(db: &DbConn) {
|
||||
name: Set("Mud Cake".to_owned()),
|
||||
price: Set(dec!(10.25)),
|
||||
gluten_free: Set(false),
|
||||
serial: Set(uuid.to_string()),
|
||||
serial: Set(uuid),
|
||||
bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)),
|
||||
..Default::default()
|
||||
};
|
||||
@ -68,7 +68,7 @@ pub async fn test_create_cake(db: &DbConn) {
|
||||
.name,
|
||||
"SeaSide Bakery"
|
||||
);
|
||||
assert_eq!(cake_model.serial, uuid.to_string());
|
||||
assert_eq!(cake_model.serial, uuid);
|
||||
|
||||
let related_bakers: Vec<baker::Model> = cake_model
|
||||
.find_related(Baker)
|
||||
|
@ -31,7 +31,7 @@ pub async fn test_create_lineitem(db: &DbConn) {
|
||||
name: Set("Mud Cake".to_owned()),
|
||||
price: Set(dec!(10.25)),
|
||||
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)),
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ pub async fn test_create_order(db: &DbConn) {
|
||||
name: Set("Mud Cake".to_owned()),
|
||||
price: Set(dec!(10.25)),
|
||||
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)),
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ pub async fn test_delete_cake(db: &DbConn) {
|
||||
name: Set("Mud Cake".to_owned()),
|
||||
price: Set(dec!(10.25)),
|
||||
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)),
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ pub async fn test_update_cake(db: &DbConn) {
|
||||
name: Set("Mud Cake".to_owned()),
|
||||
price: Set(dec!(10.25)),
|
||||
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)),
|
||||
..Default::default()
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user