diff --git a/Cargo.toml b/Cargo.toml index eb602e1b..5670161c 100644 --- a/Cargo.toml +++ b/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"] diff --git a/src/entity/column.rs b/src/entity/column.rs index adf54595..3c409e14 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -31,6 +31,7 @@ pub enum ColumnType { Json, JsonBinary, Custom(String), + Uuid, } macro_rules! bind_oper { @@ -270,6 +271,7 @@ impl From 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 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, } } } diff --git a/src/executor/query.rs b/src/executor/query.rs index 75a73463..e182494c 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -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; diff --git a/tests/common/bakery_chain/cake.rs b/tests/common/bakery_chain/cake.rs index efc55fe6..426af17a 100644 --- a/tests/common/bakery_chain/cake.rs +++ b/tests/common/bakery_chain/cake.rs @@ -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, pub gluten_free: bool, - pub serial: String, + pub serial: Uuid, } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] diff --git a/tests/common/setup/schema.rs b/tests/common/setup/schema.rs index f98caf61..b1871cfb 100644 --- a/tests/common/setup/schema.rs +++ b/tests/common/setup/schema.rs @@ -205,7 +205,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result { .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 diff --git a/tests/crud/create_cake.rs b/tests/crud/create_cake.rs index 91491560..8c76d8c1 100644 --- a/tests/crud/create_cake.rs +++ b/tests/crud/create_cake.rs @@ -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 = cake_model .find_related(Baker) diff --git a/tests/crud/create_lineitem.rs b/tests/crud/create_lineitem.rs index 61c79a65..d3f36233 100644 --- a/tests/crud/create_lineitem.rs +++ b/tests/crud/create_lineitem.rs @@ -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() }; diff --git a/tests/crud/create_order.rs b/tests/crud/create_order.rs index 487c51f9..98afba3e 100644 --- a/tests/crud/create_order.rs +++ b/tests/crud/create_order.rs @@ -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() }; diff --git a/tests/crud/deletes.rs b/tests/crud/deletes.rs index d0bf3277..ebff4b5f 100644 --- a/tests/crud/deletes.rs +++ b/tests/crud/deletes.rs @@ -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() }; diff --git a/tests/crud/updates.rs b/tests/crud/updates.rs index 497f9982..eaf305f7 100644 --- a/tests/crud/updates.rs +++ b/tests/crud/updates.rs @@ -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() };