From af0bc7a0eb03bacdb6b6561c161d3a4818821293 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 24 Aug 2022 15:19:15 +0800 Subject: [PATCH 01/12] Upgrade SeaORM root's SeaQuery to v0.27 --- Cargo.toml | 5 ++++- src/executor/cursor.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 277a2a684..0b19d1c11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.26.3", features = ["thread-safe"] } +sea-query = { version = "^0.27", features = ["thread-safe"] } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -43,6 +43,9 @@ ouroboros = "0.15" url = "^2.2" once_cell = "1.8" +[patch.crates-io] +sea-query = { git = "https://github.com/SeaQL/sea-query" } + [dev-dependencies] smol = { version = "^1.2" } smol-potat = { version = "^1.1" } diff --git a/src/executor/cursor.rs b/src/executor/cursor.rs index 264b7dc62..7f59480e2 100644 --- a/src/executor/cursor.rs +++ b/src/executor/cursor.rs @@ -415,8 +415,8 @@ mod tests { r#"FROM "cake_filling""#, r#"WHERE "cake_filling"."cake_id" > $1"#, r#"AND "cake_filling"."filling_id" > $2"#, - r#"AND ("cake_filling"."cake_id" < $3"#, - r#"AND "cake_filling"."filling_id" < $4)"#, + r#"AND "cake_filling"."cake_id" < $3"#, + r#"AND "cake_filling"."filling_id" < $4"#, r#"ORDER BY "cake_filling"."cake_id" ASC, "cake_filling"."filling_id" ASC"#, r#"LIMIT $5"#, ] From 581684c441fc3ff94cbaf1a9fe30df221d146550 Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Sat, 13 Aug 2022 01:42:09 +0300 Subject: [PATCH 02/12] issues-969 Replace sea-query-driver to sea-query-binder --- Cargo.toml | 46 ++++++++++++++++++++++++++----------- src/driver/sqlx_mysql.rs | 12 +++++----- src/driver/sqlx_postgres.rs | 14 +++++------ src/driver/sqlx_sqlite.rs | 12 +++++----- 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f119bc756..5d83249c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,9 @@ futures-util = { version = "^0.3" } log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } -sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.26.3", features = ["thread-safe"] } +sea-orm-macros = { version = "^0.9.1", path = "sea-orm-macros", optional = true } +sea-query = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.27", features = ["thread-safe"] } +sea-query-binder = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.1" } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -69,19 +70,20 @@ default = [ ] macros = ["sea-orm-macros"] mock = [] -with-json = ["serde_json", "sea-query/with-json", "chrono/serde", "sqlx?/json"] -with-chrono = ["chrono", "sea-query/with-chrono", "sqlx?/chrono"] -with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sqlx?/decimal"] -with-uuid = ["uuid", "sea-query/with-uuid", "sqlx?/uuid"] -with-time = ["time", "sea-query/with-time", "sqlx?/time"] +with-json = ["serde_json", "sea-query/with-json", "chrono/serde", "sea-query-binder/with-json", "sqlx?/json"] +with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder/with-chrono", "sqlx?/chrono"] +with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder/with-rust_decimal", "sqlx?/decimal"] +with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder/with-uuid", "sqlx?/uuid"] +with-time = ["time", "sea-query/with-time", "sea-query-binder/with-time", "sqlx?/time"] sqlx-dep = [] sqlx-all = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"] -sqlx-mysql = ["sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql"] -sqlx-postgres = ["sqlx-dep", "sea-query/sqlx-postgres", "sqlx/postgres"] -sqlx-sqlite = ["sqlx-dep", "sea-query/sqlx-sqlite", "sqlx/sqlite"] +sqlx-mysql = ["sqlx-dep", "sea-query-binder/sqlx-mysql", "sqlx/mysql"] +sqlx-postgres = ["sqlx-dep", "sea-query-binder/sqlx-postgres", "sqlx/postgres"] +sqlx-sqlite = ["sqlx-dep", "sea-query-binder/sqlx-postgres", "sqlx/sqlite"] runtime-async-std = [] runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", + "sea-query-binder/runtime-async-std-native-tls", "runtime-async-std", ] runtime-async-std-rustls = [ @@ -89,8 +91,24 @@ runtime-async-std-rustls = [ "runtime-async-std", ] runtime-actix = [] -runtime-actix-native-tls = ["sqlx/runtime-actix-native-tls", "runtime-actix"] -runtime-actix-rustls = ["sqlx/runtime-actix-rustls", "runtime-actix"] +runtime-actix-native-tls = [ + "sqlx/runtime-actix-native-tls", + "sea-query-binder/runtime-actix-native-tls", + "runtime-actix", +] +runtime-actix-rustls = [ + "sqlx/runtime-actix-rustls", + "sea-query-binder/runtime-actix-rustls", + "runtime-actix", +] runtime-tokio = [] -runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls", "runtime-tokio"] -runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls", "runtime-tokio"] +runtime-tokio-native-tls = [ + "sqlx/runtime-tokio-native-tls", + "sea-query-binder/runtime-tokio-native-tls", + "runtime-tokio", +] +runtime-tokio-rustls = [ + "sqlx/runtime-tokio-rustls", + "sea-query-binder/runtime-tokio-rustls", + "runtime-tokio", +] diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index 01b840ddb..c1526c697 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -1,3 +1,4 @@ +use sea_query::Values; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ @@ -5,8 +6,7 @@ use sqlx::{ MySql, MySqlPool, }; -sea_query::sea_query_driver_mysql!(); -use sea_query_driver_mysql::bind_query; +use sea_query_binder::{SqlxBinder, SqlxValues}; use tracing::instrument; use crate::{ @@ -215,10 +215,10 @@ impl From for ExecResult { } } -pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, MySql, MySqlArguments> { - let mut query = sqlx::query(&stmt.sql); +pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, MySql, SqlxValues> { if let Some(values) = &stmt.values { - query = bind_query(query, values); + sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) + } else { + sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) } - query } diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index bd5611485..11150fb98 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -1,12 +1,12 @@ +use sea_query::Values; +use sea_query_binder::SqlxValues; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ - postgres::{PgArguments, PgConnectOptions, PgQueryResult, PgRow}, + postgres::{PgConnectOptions, PgQueryResult, PgRow}, PgPool, Postgres, }; -sea_query::sea_query_driver_postgres!(); -use sea_query_driver_postgres::bind_query; use tracing::instrument; use crate::{ @@ -215,10 +215,10 @@ impl From for ExecResult { } } -pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Postgres, PgArguments> { - let mut query = sqlx::query(&stmt.sql); +pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Postgres, SqlxValues> { if let Some(values) = &stmt.values { - query = bind_query(query, values); + sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) + } else { + sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) } - query } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 8bf562148..985430168 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -1,3 +1,4 @@ +use sea_query::Values; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ @@ -5,8 +6,7 @@ use sqlx::{ Sqlite, SqlitePool, }; -sea_query::sea_query_driver_sqlite!(); -use sea_query_driver_sqlite::bind_query; +use sea_query_binder::SqlxValues; use tracing::instrument; use crate::{ @@ -222,10 +222,10 @@ impl From for ExecResult { } } -pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Sqlite, SqliteArguments> { - let mut query = sqlx::query(&stmt.sql); +pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Sqlite, SqlxValues> { if let Some(values) = &stmt.values { - query = bind_query(query, values); + sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) + } else { + sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) } - query } From bac22d30c5257c32021ad5e64aa32a5ec8ae548b Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Sat, 13 Aug 2022 01:50:02 +0300 Subject: [PATCH 03/12] issues-969 sea-query-binder make optional Update Cargo.toml Co-authored-by: Billy Chan --- Cargo.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d83249c0..db0976fcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ path = "src/lib.rs" [dependencies] async-stream = { version = "^0.3" } async-trait = { version = "^0.1" } -chrono = { version = "^0.4.20", default-features = false, features = ["clock"], optional = true } +chrono = { version = "^0.4", optional = true } time = { version = "^0.3", optional = true } futures = { version = "^0.3" } futures-util = { version = "^0.3" } @@ -35,7 +35,7 @@ tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.9.1", path = "sea-orm-macros", optional = true } sea-query = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.27", features = ["thread-safe"] } -sea-query-binder = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.1" } +sea-query-binder = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.1", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -70,16 +70,16 @@ default = [ ] macros = ["sea-orm-macros"] mock = [] -with-json = ["serde_json", "sea-query/with-json", "chrono/serde", "sea-query-binder/with-json", "sqlx?/json"] -with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder/with-chrono", "sqlx?/chrono"] -with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder/with-rust_decimal", "sqlx?/decimal"] -with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder/with-uuid", "sqlx?/uuid"] -with-time = ["time", "sea-query/with-time", "sea-query-binder/with-time", "sqlx?/time"] +with-json = ["serde_json", "sea-query/with-json", "chrono/serde", "sea-query-binder?/with-json", "sqlx?/json"] +with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder?/with-chrono", "sqlx?/chrono"] +with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder?/with-rust_decimal", "sqlx?/decimal"] +with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder?/with-uuid", "sqlx?/uuid"] +with-time = ["time", "sea-query/with-time", "sea-query-binder?/with-time", "sqlx?/time"] sqlx-dep = [] sqlx-all = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"] sqlx-mysql = ["sqlx-dep", "sea-query-binder/sqlx-mysql", "sqlx/mysql"] sqlx-postgres = ["sqlx-dep", "sea-query-binder/sqlx-postgres", "sqlx/postgres"] -sqlx-sqlite = ["sqlx-dep", "sea-query-binder/sqlx-postgres", "sqlx/sqlite"] +sqlx-sqlite = ["sqlx-dep", "sea-query-binder/sqlx-sqlite", "sqlx/sqlite"] runtime-async-std = [] runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", From ecbd7c2713796722afdc13a7cd9a3c051289320d Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Sat, 3 Sep 2022 18:42:51 +0300 Subject: [PATCH 04/12] issues-969 Update dependencies issues-969 Fix sqlx_query function --- Cargo.toml | 8 ++++---- src/driver/sqlx_mysql.rs | 10 +++++----- src/driver/sqlx_postgres.rs | 10 +++++----- src/driver/sqlx_sqlite.rs | 10 +++++----- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db0976fcf..8751e6604 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,16 +26,16 @@ path = "src/lib.rs" [dependencies] async-stream = { version = "^0.3" } async-trait = { version = "^0.1" } -chrono = { version = "^0.4", optional = true } +chrono = { version = "^0.4.20", default-features = false, features = ["clock"], optional = true } time = { version = "^0.3", optional = true } futures = { version = "^0.3" } futures-util = { version = "^0.3" } log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } -sea-orm-macros = { version = "^0.9.1", path = "sea-orm-macros", optional = true } -sea-query = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.27", features = ["thread-safe"] } -sea-query-binder = { git = "https://github.com/ikrivosheev/sea-query", version = "^0.1", optional = true } +sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } +sea-query = { git = "https://github.com/SeaQL/sea-query", branch = "master", version = "^0.27", features = ["thread-safe"] } +sea-query-binder = { git = "https://github.com/SeaQL/sea-query", branch = "master", version = "^0.1", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index c1526c697..c970a2c3b 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -216,9 +216,9 @@ impl From for ExecResult { } pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, MySql, SqlxValues> { - if let Some(values) = &stmt.values { - sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) - } else { - sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) - } + let values = stmt + .values + .as_ref() + .map_or(Values(Vec::new()), |values| values.clone()); + sqlx::query_with(&stmt.sql, SqlxValues(values)) } diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index 11150fb98..7737c08fe 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -216,9 +216,9 @@ impl From for ExecResult { } pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Postgres, SqlxValues> { - if let Some(values) = &stmt.values { - sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) - } else { - sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) - } + let values = stmt + .values + .as_ref() + .map_or(Values(Vec::new()), |values| values.clone()); + sqlx::query_with(&stmt.sql, SqlxValues(values)) } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 985430168..3898661af 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -223,9 +223,9 @@ impl From for ExecResult { } pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Sqlite, SqlxValues> { - if let Some(values) = &stmt.values { - sqlx::query_with(&stmt.sql, SqlxValues(values.clone())) - } else { - sqlx::query_with(&stmt.sql, SqlxValues(Values(Vec::new()))) - } + let values = stmt + .values + .as_ref() + .map_or(Values(Vec::new()), |values| values.clone()); + sqlx::query_with(&stmt.sql, SqlxValues(values)) } From c2e98b56a8023fed20ac74c90801100a3f657bad Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Fri, 9 Sep 2022 21:00:01 +0300 Subject: [PATCH 05/12] issues-969 Patch sea-orm-codegen --- sea-orm-codegen/Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index 32d539867..f79844536 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "^0.26.3" } +sea-query = { version = "^0.27", features = ["thread-safe"] } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", @@ -31,3 +31,6 @@ tracing = { version = "0.1", features = ["log"] } [dev-dependencies] pretty_assertions = { version = "^0.7" } + +[patch.crates-io] +sea-query = { git = "https://github.com/SeaQL/sea-query" } From 77bddd85a5f3916d898628d0192c9fade0fb88d8 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 22 Sep 2022 14:55:14 +0800 Subject: [PATCH 06/12] Fixup --- Cargo.toml | 8 +--- sea-orm-codegen/Cargo.toml | 5 +- sea-orm-codegen/src/entity/active_enum.rs | 11 +++-- sea-orm-codegen/src/entity/column.rs | 6 +-- sea-orm-codegen/src/entity/relation.rs | 3 +- sea-orm-codegen/src/entity/transformer.rs | 14 +++--- sea-orm-codegen/src/entity/writer.rs | 4 +- sea-orm-codegen/src/util.rs | 15 ++++++ sea-orm-macros/src/derives/active_enum.rs | 57 +++++++++++++++++++++-- src/driver/sqlx_sqlite.rs | 2 +- src/entity/active_enum.rs | 26 +++++++---- src/entity/column.rs | 44 ++++++++++++++--- src/executor/paginator.rs | 2 +- src/query/helper.rs | 2 +- src/schema/entity.rs | 21 ++++----- tests/common/features/schema.rs | 4 +- tests/common/setup/mod.rs | 8 ++-- 17 files changed, 165 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5cfb4b0d..fa32153f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.27", features = ["thread-safe"] } -sea-query-binder = { version = "^0.1", optional = true } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } +sea-query-binder = { version = "^0.1", git = "https://github.com/SeaQL/sea-query", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -45,10 +45,6 @@ ouroboros = "0.15" url = "^2.2" once_cell = "1.8" -[patch.crates-io] -sea-query = { git = "https://github.com/SeaQL/sea-query" } -sea-query-binder = { git = "https://github.com/SeaQL/sea-query" } - [dev-dependencies] smol = { version = "^1.2" } smol-potat = { version = "^1.1" } diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index f79844536..9dab2e7bf 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "^0.27", features = ["thread-safe"] } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", @@ -31,6 +31,3 @@ tracing = { version = "0.1", features = ["log"] } [dev-dependencies] pretty_assertions = { version = "^0.7" } - -[patch.crates-io] -sea-query = { git = "https://github.com/SeaQL/sea-query" } diff --git a/sea-orm-codegen/src/entity/active_enum.rs b/sea-orm-codegen/src/entity/active_enum.rs index d4a7e6003..c0d285f76 100644 --- a/sea-orm-codegen/src/entity/active_enum.rs +++ b/sea-orm-codegen/src/entity/active_enum.rs @@ -2,19 +2,20 @@ use crate::WithSerde; use heck::CamelCase; use proc_macro2::TokenStream; use quote::{format_ident, quote}; +use sea_query::DynIden; #[derive(Clone, Debug)] pub struct ActiveEnum { - pub(crate) enum_name: String, - pub(crate) values: Vec, + pub(crate) enum_name: DynIden, + pub(crate) values: Vec, } impl ActiveEnum { pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool) -> TokenStream { - let enum_name = &self.enum_name; + let enum_name = &self.enum_name.to_string(); let enum_iden = format_ident!("{}", enum_name.to_camel_case()); - let values = &self.values; - let variants = self.values.iter().map(|v| v.trim()).map(|v| { + let values: Vec = self.values.iter().map(|v| v.to_string()).collect(); + let variants = values.iter().map(|v| v.trim()).map(|v| { if v.chars().all(|c| c.is_numeric()) { format_ident!("_{}", v) } else { diff --git a/sea-orm-codegen/src/entity/column.rs b/sea-orm-codegen/src/entity/column.rs index 2060853e5..3c4d739cd 100644 --- a/sea-orm-codegen/src/entity/column.rs +++ b/sea-orm-codegen/src/entity/column.rs @@ -70,7 +70,7 @@ impl Column { ColumnType::Uuid => "Uuid".to_owned(), ColumnType::Binary(_) | ColumnType::VarBinary(_) => "Vec".to_owned(), ColumnType::Boolean => "bool".to_owned(), - ColumnType::Enum(name, _) => name.to_camel_case(), + ColumnType::Enum { name, .. } => name.to_string().to_camel_case(), _ => unimplemented!(), } .parse() @@ -146,8 +146,8 @@ impl Column { let s = s.to_string(); quote! { ColumnType::Custom(#s.to_owned()).def() } } - ColumnType::Enum(enum_name, _) => { - let enum_ident = format_ident!("{}", enum_name.to_camel_case()); + ColumnType::Enum { name, .. } => { + let enum_ident = format_ident!("{}", name.to_string().to_camel_case()); quote! { #enum_ident::db_type() } } #[allow(unreachable_patterns)] diff --git a/sea-orm-codegen/src/entity/relation.rs b/sea-orm-codegen/src/entity/relation.rs index 57722e506..185af3178 100644 --- a/sea-orm-codegen/src/entity/relation.rs +++ b/sea-orm-codegen/src/entity/relation.rs @@ -1,3 +1,4 @@ +use crate::util::unpack_table_ref; use heck::{CamelCase, SnakeCase}; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; @@ -155,7 +156,7 @@ impl Relation { impl From<&TableForeignKey> for Relation { fn from(tbl_fk: &TableForeignKey) -> Self { let ref_table = match tbl_fk.get_ref_table() { - Some(s) => s, + Some(s) => unpack_table_ref(s), None => panic!("RefTable should not be empty"), }; let columns = tbl_fk.get_columns(); diff --git a/sea-orm-codegen/src/entity/transformer.rs b/sea-orm-codegen/src/entity/transformer.rs index 43cc111b3..0c0da7d50 100644 --- a/sea-orm-codegen/src/entity/transformer.rs +++ b/sea-orm-codegen/src/entity/transformer.rs @@ -1,6 +1,6 @@ use crate::{ - ActiveEnum, Column, ConjunctRelation, Entity, EntityWriter, Error, PrimaryKey, Relation, - RelationType, + util::unpack_table_ref, ActiveEnum, Column, ConjunctRelation, Entity, EntityWriter, Error, + PrimaryKey, Relation, RelationType, }; use sea_query::{ColumnSpec, TableCreateStatement}; use std::collections::HashMap; @@ -59,12 +59,12 @@ impl EntityTransformer { col }) .map(|col| { - if let sea_query::ColumnType::Enum(enum_name, values) = &col.col_type { + if let sea_query::ColumnType::Enum { name, variants } = &col.col_type { enums.insert( - enum_name.clone(), + name.to_string(), ActiveEnum { - enum_name: enum_name.clone(), - values: values.clone(), + enum_name: name.clone(), + values: variants.clone(), }, ); } @@ -77,7 +77,7 @@ impl EntityTransformer { .iter() .map(|fk_create_stmt| fk_create_stmt.get_foreign_key()) .map(|tbl_fk| { - let ref_tbl = tbl_fk.get_ref_table().unwrap(); + let ref_tbl = unpack_table_ref(tbl_fk.get_ref_table().unwrap()); if let Some(count) = ref_table_counts.get_mut(&ref_tbl) { if *count == 0 { *count = 1; diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 19722e183..2d7bc87c3 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -363,8 +363,8 @@ impl EntityWriter { .columns .iter() .fold(TokenStream::new(), |mut ts, col| { - if let sea_query::ColumnType::Enum(enum_name, _) = &col.col_type { - let enum_name = format_ident!("{}", enum_name.to_camel_case()); + if let sea_query::ColumnType::Enum { name, .. } = &col.col_type { + let enum_name = format_ident!("{}", name.to_string().to_camel_case()); ts.extend(vec![quote! { use super::sea_orm_active_enums::#enum_name; }]); diff --git a/sea-orm-codegen/src/util.rs b/sea-orm-codegen/src/util.rs index 34c46c547..5d74f3d4f 100644 --- a/sea-orm-codegen/src/util.rs +++ b/sea-orm-codegen/src/util.rs @@ -1,3 +1,5 @@ +use sea_query::TableRef; + pub(crate) fn escape_rust_keyword(string: T) -> String where T: ToString, @@ -21,3 +23,16 @@ pub(crate) const RUST_KEYWORDS: [&str; 49] = [ ]; pub(crate) const RUST_SPECIAL_KEYWORDS: [&str; 3] = ["crate", "Self", "self"]; + +pub(crate) fn unpack_table_ref(table_ref: &TableRef) -> String { + match table_ref { + TableRef::Table(tbl) + | TableRef::SchemaTable(_, tbl) + | TableRef::DatabaseSchemaTable(_, _, tbl) + | TableRef::TableAlias(tbl, _) + | TableRef::SchemaTableAlias(_, tbl, _) + | TableRef::DatabaseSchemaTableAlias(_, _, tbl, _) + | TableRef::SubQuery(_, tbl) + | TableRef::ValuesList(_, tbl) => tbl.to_string(), + } +} diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index cbc9c4b0e..c7693ae3c 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -1,6 +1,6 @@ use heck::CamelCase; use proc_macro2::TokenStream; -use quote::{quote, quote_spanned}; +use quote::{format_ident, quote, quote_spanned}; use syn::{parse, punctuated::Punctuated, token::Comma, Expr, Lit, LitInt, LitStr, Meta, UnOp}; enum Error { @@ -59,7 +59,10 @@ impl ActiveEnum { match s.as_ref() { "Enum" => { db_type = Ok(quote! { - Enum(Self::name(), Self::values()) + Enum { + name: Self::name(), + variants: Self::iden_values(), + } }) } _ => { @@ -227,13 +230,59 @@ impl ActiveEnum { quote! { v } }; + let enum_name_iden = format_ident!("{}Enum", ident); + + let str_variants: Vec = variants + .iter() + .filter_map(|variant| { + variant + .string_value + .as_ref() + .map(|string_value| string_value.value()) + }) + .collect(); + + let impl_enum_variant_iden = if !str_variants.is_empty() { + let enum_variant_iden = format_ident!("{}Variant", ident); + let enum_variants: Vec = str_variants + .iter() + .map(|v| format_ident!("{}", v.to_camel_case())) + .collect(); + + quote!( + #[derive(Debug, Clone, PartialEq, Eq, EnumIter, Iden)] + pub enum #enum_variant_iden { + #( + #[iden = #str_variants] + #enum_variants, + )* + } + + impl #ident { + pub fn iden_values() -> Vec { + <#enum_variant_iden as sea_orm::strum::IntoEnumIterator>::iter() + .map(|v| sea_orm::sea_query::SeaRc::new(v) as sea_orm::sea_query::DynIden) + .collect() + } + } + ) + } else { + quote!() + }; + quote!( + #[derive(Debug, Clone, PartialEq, Eq, Iden)] + #[iden = #enum_name] + pub struct #enum_name_iden; + + #impl_enum_variant_iden + #[automatically_derived] impl sea_orm::ActiveEnum for #ident { type Value = #rs_type; - fn name() -> String { - #enum_name.to_owned() + fn name() -> sea_orm::sea_query::DynIden { + sea_orm::sea_query::SeaRc::new(#enum_name_iden) as sea_orm::sea_query::DynIden } fn to_value(&self) -> Self::Value { diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 3898661af..2d3a48149 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -2,7 +2,7 @@ use sea_query::Values; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ - sqlite::{SqliteArguments, SqliteConnectOptions, SqliteQueryResult, SqliteRow}, + sqlite::{SqliteConnectOptions, SqliteQueryResult, SqliteRow}, Sqlite, SqlitePool, }; diff --git a/src/entity/active_enum.rs b/src/entity/active_enum.rs index 2e03d4fd9..86bd126b5 100644 --- a/src/entity/active_enum.rs +++ b/src/entity/active_enum.rs @@ -1,5 +1,5 @@ use crate::{ColumnDef, DbErr, Iterable, TryGetable}; -use sea_query::{Nullable, Value, ValueType}; +use sea_query::{DynIden, Nullable, Value, ValueType}; /// A Rust representation of enum defined in database. /// @@ -37,13 +37,16 @@ use sea_query::{Nullable, Value, ValueType}; /// Small, /// } /// +/// #[derive(Debug, Iden)] +/// pub struct CategoryEnum; +/// /// impl ActiveEnum for Category { /// // The macro attribute `rs_type` is being pasted here /// type Value = String; /// /// // Will be atomically generated by `DeriveActiveEnum` -/// fn name() -> String { -/// "category".to_owned() +/// fn name() -> DynIden { +/// SeaRc::new(CategoryEnum) /// } /// /// // Will be atomically generated by `DeriveActiveEnum` @@ -109,7 +112,7 @@ pub trait ActiveEnum: Sized + Iterable { type Value: Into + ValueType + Nullable + TryGetable; /// Get the name of enum - fn name() -> String; + fn name() -> DynIden; /// Convert enum variant into the corresponding value. fn to_value(&self) -> Self::Value; @@ -134,7 +137,7 @@ pub trait ActiveEnum: Sized + Iterable { #[cfg(test)] mod tests { use crate as sea_orm; - use crate::{entity::prelude::*, *}; + use crate::{entity::prelude::*, sea_query::SeaRc, *}; use pretty_assertions::assert_eq; #[test] @@ -145,11 +148,15 @@ mod tests { Small, } + #[derive(Debug, Iden)] + #[iden = "category"] + pub struct CategoryEnum; + impl ActiveEnum for Category { type Value = String; - fn name() -> String { - "category".to_owned() + fn name() -> DynIden { + SeaRc::new(CategoryEnum) } fn to_value(&self) -> Self::Value { @@ -226,7 +233,10 @@ mod tests { assert_eq!(Category::db_type(), ColumnType::String(Some(1)).def()); assert_eq!(DeriveCategory::db_type(), ColumnType::String(Some(1)).def()); - assert_eq!(Category::name(), DeriveCategory::name()); + assert_eq!( + Category::name().to_string(), + DeriveCategory::name().to_string() + ); assert_eq!(Category::values(), DeriveCategory::values()); } diff --git a/src/entity/column.rs b/src/entity/column.rs index 92e32fb6c..802a3de29 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -13,7 +13,7 @@ pub struct ColumnDef { } /// The type of column as defined in the SQL format -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub enum ColumnType { /// `CHAR` type of specified fixed length Char(Option), @@ -78,7 +78,39 @@ pub enum ColumnType { /// A Universally Unique IDentifier that is specified in RFC 4122 Uuid, /// `ENUM` data type with name and variants - Enum(String, Vec), + Enum { + /// Name of enum + name: DynIden, + /// Variants of enum + variants: Vec, + }, +} + +impl PartialEq for ColumnType { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::Char(l0), Self::Char(r0)) => l0 == r0, + (Self::String(l0), Self::String(r0)) => l0 == r0, + (Self::Decimal(l0), Self::Decimal(r0)) => l0 == r0, + (Self::Money(l0), Self::Money(r0)) => l0 == r0, + (Self::Custom(l0), Self::Custom(r0)) => l0 == r0, + ( + Self::Enum { + name: l_name, + variants: l_variants, + }, + Self::Enum { + name: r_name, + variants: r_variants, + }, + ) => { + l_name.to_string() == r_name.to_string() + && l_variants.iter().map(|v| v.to_string()).collect::>() + == r_variants.iter().map(|v| v.to_string()).collect::>() + } + _ => core::mem::discriminant(self) == core::mem::discriminant(other), + } + } } macro_rules! bind_oper { @@ -318,9 +350,9 @@ impl ColumnType { } } - pub(crate) fn get_enum_name(&self) -> Option<&String> { + pub(crate) fn get_enum_name(&self) -> Option<&DynIden> { match self { - ColumnType::Enum(s, _) => Some(s), + ColumnType::Enum { name, .. } => Some(name), _ => None, } } @@ -399,7 +431,7 @@ impl From for sea_query::ColumnType { sea_query::ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(&s))) } ColumnType::Uuid => sea_query::ColumnType::Uuid, - ColumnType::Enum(name, variants) => sea_query::ColumnType::Enum(name, variants), + ColumnType::Enum { name, variants } => sea_query::ColumnType::Enum { name, variants }, } } } @@ -437,7 +469,7 @@ impl From for ColumnType { sea_query::ColumnType::JsonBinary => Self::JsonBinary, sea_query::ColumnType::Custom(s) => Self::Custom(s.to_string()), sea_query::ColumnType::Uuid => Self::Uuid, - sea_query::ColumnType::Enum(name, variants) => Self::Enum(name, variants), + sea_query::ColumnType::Enum { name, variants } => Self::Enum { name, variants }, _ => unimplemented!(), } } diff --git a/src/executor/paginator.rs b/src/executor/paginator.rs index a296efa5e..d3f3e8b5c 100644 --- a/src/executor/paginator.rs +++ b/src/executor/paginator.rs @@ -251,7 +251,7 @@ where { type Selector = S; fn paginate(self, db: &'db C, page_size: u64) -> Paginator<'db, C, S> { - let sql = &self.stmt.sql[6..]; + let sql = &self.stmt.sql[7..]; let mut query = SelectStatement::new(); query.expr(if let Some(values) = self.stmt.values { Expr::cust_with_values(sql, values.0) diff --git a/src/query/helper.rs b/src/query/helper.rs index f476d60cf..89dd61f19 100644 --- a/src/query/helper.rs +++ b/src/query/helper.rs @@ -581,7 +581,7 @@ where let col_def = col.def(); let col_type = col_def.get_column_type(); match col_type.get_enum_name() { - Some(enum_name) => f(expr, SeaRc::new(Alias::new(enum_name))), + Some(enum_name) => f(expr, SeaRc::clone(enum_name)), None => expr.into(), } } diff --git a/src/schema/entity.rs b/src/schema/entity.rs index c09862be2..089a4fe53 100644 --- a/src/schema/entity.rs +++ b/src/schema/entity.rs @@ -1,11 +1,10 @@ use crate::{ - unpack_table_ref, ActiveEnum, ColumnTrait, ColumnType, DbBackend, EntityTrait, Identity, - Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, RelationTrait, Schema, + unpack_table_ref, ActiveEnum, ColumnDef, ColumnTrait, ColumnType, DbBackend, EntityTrait, + Identity, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, RelationTrait, Schema, }; use sea_query::{ extension::postgres::{Type, TypeCreateStatement}, - Alias, ColumnDef, ForeignKeyCreateStatement, Iden, Index, IndexCreateStatement, - TableCreateStatement, + ForeignKeyCreateStatement, Iden, Index, IndexCreateStatement, TableCreateStatement, }; impl Schema { @@ -57,13 +56,10 @@ where pub(crate) fn create_enum_from_column_type(col_type: &ColumnType) -> TypeCreateStatement { let (name, values) = match col_type { - ColumnType::Enum(s, v) => (s.as_str(), v), + ColumnType::Enum { name, variants } => (name.clone(), variants.clone()), _ => panic!("Should be ColumnType::Enum"), }; - Type::create() - .as_enum(Alias::new(name)) - .values(values.iter().map(|val| Alias::new(val.as_str()))) - .to_owned() + Type::create().as_enum(name).values(values).to_owned() } #[allow(clippy::needless_borrow)] @@ -78,7 +74,7 @@ where for col in E::Column::iter() { let col_def = col.def(); let col_type = col_def.get_column_type(); - if !matches!(col_type, ColumnType::Enum(_, _)) { + if !matches!(col_type, ColumnType::Enum { .. }) { continue; } let stmt = create_enum_from_column_type(&col_type); @@ -123,11 +119,12 @@ where for column in E::Column::iter() { let orm_column_def = column.def(); let types = match orm_column_def.col_type { - ColumnType::Enum(s, variants) => match backend { + ColumnType::Enum { name, variants } => match backend { DbBackend::MySql => { + let variants: Vec = variants.iter().map(|v| v.to_string()).collect(); ColumnType::Custom(format!("ENUM('{}')", variants.join("', '"))) } - DbBackend::Postgres => ColumnType::Custom(s), + DbBackend::Postgres => ColumnType::Custom(name.to_string()), DbBackend::Sqlite => ColumnType::Text, } .into(), diff --git a/tests/common/features/schema.rs b/tests/common/features/schema.rs index b6bf9ae47..f14568bcb 100644 --- a/tests/common/features/schema.rs +++ b/tests/common/features/schema.rs @@ -166,7 +166,7 @@ pub async fn create_active_enum_table(db: &DbConn) -> Result .col(ColumnDef::new(active_enum::Column::Color).integer()) .col( ColumnDef::new(active_enum::Column::Tea) - .enumeration("tea", vec!["EverydayTea", "BreakfastTea"]), + .enumeration(TeaEnum, [TeaVariant::EverydayTea, TeaVariant::BreakfastTea]), ) .to_owned(); @@ -192,7 +192,7 @@ pub async fn create_active_enum_child_table(db: &DbConn) -> Result DatabaseConnection { @@ -88,15 +88,15 @@ where for col in E::Column::iter() { let col_def = col.def(); let col_type = col_def.get_column_type(); - if !matches!(col_type, ColumnType::Enum(_, _)) { + if !matches!(col_type, ColumnType::Enum { .. }) { continue; } let name = match col_type { - ColumnType::Enum(s, _) => s.as_str(), + ColumnType::Enum { name, .. } => name, _ => unreachable!(), }; let drop_type_stmt = Type::drop() - .name(Alias::new(name)) + .name(SeaRc::clone(name)) .if_exists() .cascade() .to_owned(); From 671d79469afbcdc05a45200eb5d73c9232abc824 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 17 Oct 2022 17:25:35 +0800 Subject: [PATCH 07/12] Fixup --- Cargo.toml | 8 ++++++-- issues/324/src/model.rs | 4 ++++ issues/400/src/model.rs | 4 ++++ sea-orm-codegen/Cargo.toml | 2 +- sea-orm-macros/src/derives/active_enum.rs | 4 ++++ sea-orm-macros/src/derives/try_getable_from_json.rs | 4 ++++ src/driver/sqlx_mysql.rs | 4 ++-- src/driver/sqlx_postgres.rs | 2 +- src/entity/active_enum.rs | 5 ++++- src/query/insert.rs | 2 +- src/query/update.rs | 4 ++-- src/schema/entity.rs | 6 +++--- tests/common/features/json_vec.rs | 4 ++++ 13 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa32153f7..1a0795de4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } -sea-query-binder = { version = "^0.1", git = "https://github.com/SeaQL/sea-query", optional = true } +sea-query = { version = "^0.27", features = ["thread-safe"] } +sea-query-binder = { version = "^0.2", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -45,6 +45,10 @@ ouroboros = "0.15" url = "^2.2" once_cell = "1.8" +[patch.crates-io] +sea-query = { git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals" } +sea-query-binder = { git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals" } + [dev-dependencies] smol = { version = "^1.2" } smol-potat = { version = "^1.1" } diff --git a/issues/324/src/model.rs b/issues/324/src/model.rs index 9ec35a077..ad12d15e7 100644 --- a/issues/324/src/model.rs +++ b/issues/324/src/model.rs @@ -72,6 +72,10 @@ macro_rules! into_sea_query_value { stringify!($newtype).to_owned() } + fn array_type() -> sea_orm::sea_query::ArrayType { + sea_orm::sea_query::ArrayType::$name + } + fn column_type() -> sea_orm::sea_query::ColumnType { sea_orm::sea_query::ColumnType::$name } diff --git a/issues/400/src/model.rs b/issues/400/src/model.rs index a53eeb740..4a207ce10 100644 --- a/issues/400/src/model.rs +++ b/issues/400/src/model.rs @@ -73,6 +73,10 @@ impl sea_orm::sea_query::ValueType for AccountId { stringify!(AccountId).to_owned() } + fn array_type() -> sea_orm::sea_query::ArrayType { + sea_orm::sea_query::ArrayType::Uuid + } + fn column_type() -> sea_orm::sea_query::ColumnType { sea_orm::sea_query::ColumnType::Uuid } diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index 9dab2e7bf..b17a19cb8 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } +sea-query = { version = "^0.27", features = ["thread-safe"] } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index c7693ae3c..7d72c67be 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -335,6 +335,10 @@ impl ActiveEnum { <::Value as sea_orm::sea_query::ValueType>::type_name() } + fn array_type() -> sea_orm::sea_query::ArrayType { + unimplemented!("Array of Enum is not supported") + } + fn column_type() -> sea_orm::sea_query::ColumnType { ::db_type() .get_column_type() diff --git a/sea-orm-macros/src/derives/try_getable_from_json.rs b/sea-orm-macros/src/derives/try_getable_from_json.rs index 957cee3dd..43cdf6373 100644 --- a/sea-orm-macros/src/derives/try_getable_from_json.rs +++ b/sea-orm-macros/src/derives/try_getable_from_json.rs @@ -28,6 +28,10 @@ pub fn expand_derive_from_json_query_result(ident: Ident) -> syn::Result sea_orm::sea_query::ArrayType { + sea_orm::sea_query::ArrayType::Json + } + fn column_type() -> sea_orm::sea_query::ColumnType { sea_orm::sea_query::ColumnType::Json } diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index c970a2c3b..ac53f5569 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -2,11 +2,11 @@ use sea_query::Values; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ - mysql::{MySqlArguments, MySqlConnectOptions, MySqlQueryResult, MySqlRow}, + mysql::{MySqlConnectOptions, MySqlQueryResult, MySqlRow}, MySql, MySqlPool, }; -use sea_query_binder::{SqlxBinder, SqlxValues}; +use sea_query_binder::SqlxValues; use tracing::instrument; use crate::{ diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index 7737c08fe..7ae5cd403 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -1,5 +1,4 @@ use sea_query::Values; -use sea_query_binder::SqlxValues; use std::{future::Future, pin::Pin, sync::Arc}; use sqlx::{ @@ -7,6 +6,7 @@ use sqlx::{ PgPool, Postgres, }; +use sea_query_binder::SqlxValues; use tracing::instrument; use crate::{ diff --git a/src/entity/active_enum.rs b/src/entity/active_enum.rs index 86bd126b5..19a48a1bc 100644 --- a/src/entity/active_enum.rs +++ b/src/entity/active_enum.rs @@ -14,7 +14,10 @@ use sea_query::{DynIden, Nullable, Value, ValueType}; /// > See [DeriveActiveEnum](sea_orm_macros::DeriveActiveEnum) for the full specification of macro attributes. /// /// ```rust -/// use sea_orm::entity::prelude::*; +/// use sea_orm::{ +/// entity::prelude::*, +/// sea_query::{DynIden, SeaRc}, +/// }; /// /// // Using the derive macro /// #[derive(Debug, PartialEq, EnumIter, DeriveActiveEnum)] diff --git a/src/query/insert.rs b/src/query/insert.rs index 3ca6f82b0..f95e44640 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -138,7 +138,7 @@ where } } self.query.columns(columns); - self.query.exprs_panic(values); + self.query.values_panic(values); self } diff --git a/src/query/update.rs b/src/query/update.rs index 63adac7ac..b5d404a05 100644 --- a/src/query/update.rs +++ b/src/query/update.rs @@ -110,7 +110,7 @@ where let av = self.model.get(col); if av.is_set() { let expr = cast_text_as_enum(Expr::val(av.into_value().unwrap()), &col); - self.query.value_expr(col, expr); + self.query.value(col, expr); } } self @@ -200,7 +200,7 @@ where where T: IntoIden, { - self.query.col_expr(col, expr); + self.query.value(col, expr); self } } diff --git a/src/schema/entity.rs b/src/schema/entity.rs index 089a4fe53..28bca9d5a 100644 --- a/src/schema/entity.rs +++ b/src/schema/entity.rs @@ -1,10 +1,10 @@ use crate::{ - unpack_table_ref, ActiveEnum, ColumnDef, ColumnTrait, ColumnType, DbBackend, EntityTrait, - Identity, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, RelationTrait, Schema, + unpack_table_ref, ActiveEnum, ColumnTrait, ColumnType, DbBackend, EntityTrait, Identity, + Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, RelationTrait, Schema, }; use sea_query::{ extension::postgres::{Type, TypeCreateStatement}, - ForeignKeyCreateStatement, Iden, Index, IndexCreateStatement, TableCreateStatement, + ColumnDef, ForeignKeyCreateStatement, Iden, Index, IndexCreateStatement, TableCreateStatement, }; impl Schema { diff --git a/tests/common/features/json_vec.rs b/tests/common/features/json_vec.rs index aebd67990..8e9aca5bd 100644 --- a/tests/common/features/json_vec.rs +++ b/tests/common/features/json_vec.rs @@ -45,6 +45,10 @@ impl sea_query::ValueType for StringVec { stringify!(StringVec).to_owned() } + fn array_type() -> sea_orm::sea_query::ArrayType { + sea_orm::sea_query::ArrayType::String + } + fn column_type() -> sea_query::ColumnType { sea_query::ColumnType::String(None) } From 468cbb9baf76d605f3e0ce18b65902ed69681906 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 17 Oct 2022 22:00:42 +0800 Subject: [PATCH 08/12] Fixup --- Cargo.toml | 8 ++------ sea-orm-migration/Cargo.toml | 2 +- src/executor/paginator.rs | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af17dac61..603e72bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.27", features = ["thread-safe"] } -sea-query-binder = { version = "^0.2", optional = true } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals", features = ["thread-safe"] } +sea-query-binder = { version = "^0.2", git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } @@ -46,10 +46,6 @@ url = "^2.2" once_cell = "1.8" thiserror = "^1" -[patch.crates-io] -sea-query = { git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals" } -sea-query-binder = { git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals" } - [dev-dependencies] smol = { version = "^1.2" } smol-potat = { version = "^1.1" } diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 4abed0401..0ca35e660 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -25,7 +25,7 @@ clap = { version = "^3.2", features = ["env", "derive"] } dotenvy = { version = "^0.15" } sea-orm = { version = "^0.10.0", path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { version = "^0.10.0", path = "../sea-orm-cli", default-features = false } -sea-schema = { version = "^0.9.3" } +sea-schema = { version = "^0.9.3", git = "https://github.com/SeaQL/sea-schema", branch = "sea-query-0.27" } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/src/executor/paginator.rs b/src/executor/paginator.rs index fe5b9272e..3ec3b50f5 100644 --- a/src/executor/paginator.rs +++ b/src/executor/paginator.rs @@ -251,7 +251,7 @@ where { type Selector = S; fn paginate(self, db: &'db C, page_size: u64) -> Paginator<'db, C, S> { - let sql = &self.stmt.sql.trim()[7..]; + let sql = &self.stmt.sql.trim()[6..].trim(); let mut query = SelectStatement::new(); query.expr(if let Some(values) = self.stmt.values { Expr::cust_with_values(sql, values.0) From e5186cdb9e5b6fc15d4f75b05974da54f17cd7ca Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Mon, 17 Oct 2022 21:53:22 +0300 Subject: [PATCH 09/12] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 603e72bb9..cb865c1a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ default = [ ] macros = ["sea-orm-macros"] mock = [] -with-json = ["serde_json", "sea-query/with-json", "chrono/serde", "sea-query-binder?/with-json", "sqlx?/json"] +with-json = ["serde_json", "sea-query/with-json", "chrono?/serde", "time?/serde", "sea-query-binder?/with-json", "sqlx?/json"] with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder?/with-chrono", "sqlx?/chrono"] with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder?/with-rust_decimal", "sqlx?/decimal"] with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder?/with-uuid", "sqlx?/uuid"] From 44690994fe4d3625e7fcff4b9d897488ac6fd11f Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Mon, 17 Oct 2022 21:55:23 +0300 Subject: [PATCH 10/12] Update Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb865c1a4..af45dde21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals", features = ["thread-safe"] } -sea-query-binder = { version = "^0.2", git = "https://github.com/SeaQL/sea-query", branch = "sqlite-bind-decimals", optional = true } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", branch = "master", features = ["thread-safe"] } +sea-query-binder = { version = "^0.2", git = "https://github.com/SeaQL/sea-query", branch = "master", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } From 34ba0229cdb8ceb3d984ff0e416810e7a0312b4a Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 18 Oct 2022 18:48:17 +0800 Subject: [PATCH 11/12] Refactoring --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af45dde21..3c3e7fd5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = { version = "^0.4" } tracing = { version = "^0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.10.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", branch = "master", features = ["thread-safe"] } -sea-query-binder = { version = "^0.2", git = "https://github.com/SeaQL/sea-query", branch = "master", optional = true } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } +sea-query-binder = { version = "^0.2", git = "https://github.com/SeaQL/sea-query", optional = true } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0", optional = true } From 4df9a2672a35b7254952ba9223614a5467adbd7d Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 18 Oct 2022 19:03:50 +0800 Subject: [PATCH 12/12] Fixup --- sea-orm-cli/Cargo.toml | 2 +- sea-orm-codegen/Cargo.toml | 2 +- sea-orm-migration/Cargo.toml | 2 +- src/executor/paginator.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 710f84bec..2307cc4f7 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -35,7 +35,7 @@ clap = { version = "^3.2", features = ["env", "derive"] } dotenvy = { version = "^0.15", optional = true } async-std = { version = "^1.9", features = [ "attributes", "tokio1" ], optional = true } sea-orm-codegen = { version = "^0.10.0", path = "../sea-orm-codegen", optional = true } -sea-schema = { version = "^0.9.3" } +sea-schema = { version = "^0.10.0", git = "https://github.com/SeaQL/sea-schema", branch = "sea-query-0.27" } sqlx = { version = "^0.6", default-features = false, features = [ "mysql", "postgres" ], optional = true } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing = { version = "0.1" } diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index b17a19cb8..9dab2e7bf 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "^0.27", features = ["thread-safe"] } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query", features = ["thread-safe"] } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 0ca35e660..45f9ae3ee 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -25,7 +25,7 @@ clap = { version = "^3.2", features = ["env", "derive"] } dotenvy = { version = "^0.15" } sea-orm = { version = "^0.10.0", path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { version = "^0.10.0", path = "../sea-orm-cli", default-features = false } -sea-schema = { version = "^0.9.3", git = "https://github.com/SeaQL/sea-schema", branch = "sea-query-0.27" } +sea-schema = { version = "^0.10.0", git = "https://github.com/SeaQL/sea-schema", branch = "sea-query-0.27" } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/src/executor/paginator.rs b/src/executor/paginator.rs index 562dfbdc9..60811323a 100644 --- a/src/executor/paginator.rs +++ b/src/executor/paginator.rs @@ -253,7 +253,7 @@ where type Selector = S; fn paginate(self, db: &'db C, page_size: u64) -> Paginator<'db, C, S> { assert!(page_size != 0, "page_size should not be zero"); - let sql = &self.stmt.sql.trim()[6..]; + let sql = &self.stmt.sql.trim()[6..].trim(); let mut query = SelectStatement::new(); query.expr(if let Some(values) = self.stmt.values { Expr::cust_with_values(sql, values.0)