diff --git a/Cargo.toml b/Cargo.toml index 86e54f9e..a569bf26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ members = [ [package] name = "sea-schema" -version = "0.9.4" +version = "0.10.0" authors = [ "Chris Tsang " ] edition = "2021" description = "🌿 SQL schema definition and discovery" @@ -35,7 +35,8 @@ path = "src/lib.rs" [dependencies] futures = { version = "0.3", optional = true } sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" } -sea-query = { version = "^0.26.0" } +sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query" } +sea-query-binder = { version = "^0.2", optional = true, git = "https://github.com/SeaQL/sea-query" } serde = { version = "^1", features = ["derive"], optional = true } sqlx = { version = "^0.6", optional = true } log = { version = "^0.4", optional = true } @@ -58,27 +59,45 @@ sqlx-mysql = [ "mysql", "futures", "sqlx-dep", - "sea-query/sqlx-mysql", + "sea-query-binder/sqlx-mysql", "sqlx/mysql", ] sqlx-postgres = [ "postgres", "futures", "sqlx-dep", - "sea-query/sqlx-postgres", + "sea-query-binder/sqlx-postgres", "sqlx/postgres", ] sqlx-sqlite = [ "sqlite", "futures", "sqlx-dep", - "sea-query/sqlx-sqlite", + "sea-query-binder/sqlx-sqlite", "sqlx/sqlite", ] -runtime-actix-native-tls = ["sqlx/runtime-actix-native-tls"] -runtime-async-std-native-tls = ["sqlx/runtime-async-std-native-tls"] -runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls"] -runtime-actix-rustls = ["sqlx/runtime-actix-rustls"] -runtime-async-std-rustls = ["sqlx/runtime-async-std-rustls"] -runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"] +runtime-actix-native-tls = [ + "sqlx/runtime-actix-native-tls", + "sea-query-binder/runtime-actix-native-tls", +] +runtime-async-std-native-tls = [ + "sqlx/runtime-async-std-native-tls", + "sea-query-binder/runtime-async-std-native-tls", +] +runtime-tokio-native-tls = [ + "sqlx/runtime-tokio-native-tls", + "sea-query-binder/runtime-tokio-native-tls", +] +runtime-actix-rustls = [ + "sqlx/runtime-actix-rustls", + "sea-query-binder/runtime-actix-rustls", +] +runtime-async-std-rustls = [ + "sqlx/runtime-async-std-rustls", + "sea-query-binder/runtime-async-std-rustls", +] +runtime-tokio-rustls = [ + "sqlx/runtime-tokio-rustls", + "sea-query-binder/runtime-tokio-rustls", +] with-serde = ["serde"] diff --git a/src/mysql/discovery/executor/real.rs b/src/mysql/discovery/executor/real.rs index da85ff52..7c7666aa 100644 --- a/src/mysql/discovery/executor/real.rs +++ b/src/mysql/discovery/executor/real.rs @@ -1,9 +1,7 @@ use sea_query::{MysqlQueryBuilder, SelectStatement}; +use sea_query_binder::SqlxBinder; use sqlx::{mysql::MySqlRow, MySqlPool}; -sea_query::sea_query_driver_mysql!(); -use sea_query_driver_mysql::bind_query; - use crate::debug_print; pub struct Executor { @@ -22,11 +20,10 @@ impl IntoExecutor for MySqlPool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(MysqlQueryBuilder); + let (sql, values) = select.build_sqlx(MysqlQueryBuilder); debug_print!("{}, {:?}", sql, values); - let query = bind_query(sqlx::query(&sql), &values); - query + sqlx::query_with(&sql, values) .fetch_all(&mut self.pool.acquire().await.unwrap()) .await .unwrap() diff --git a/src/mysql/query/version.rs b/src/mysql/query/version.rs index f42f19e0..5cad3e15 100644 --- a/src/mysql/query/version.rs +++ b/src/mysql/query/version.rs @@ -4,7 +4,6 @@ use sea_query::{Func, Query, SelectStatement}; #[derive(sea_query::Iden)] enum MysqlFunc { - #[iden = "version()"] Version, } diff --git a/src/mysql/writer/column.rs b/src/mysql/writer/column.rs index e0c4ddc1..ef77ffeb 100644 --- a/src/mysql/writer/column.rs +++ b/src/mysql/writer/column.rs @@ -1,5 +1,7 @@ use crate::mysql::def::{CharSet, ColumnInfo, NumericAttr, StringAttr, Type}; -use sea_query::{Alias, BlobSize, ColumnDef, EscapeBuilder, Iden, MysqlQueryBuilder}; +use sea_query::{ + Alias, BlobSize, ColumnDef, DynIden, EscapeBuilder, Iden, IntoIden, MysqlQueryBuilder, +}; use std::fmt::Write; impl ColumnInfo { @@ -232,7 +234,13 @@ impl ColumnInfo { col_def.blob(BlobSize::Long); } Type::Enum(enum_attr) => { - col_def.enumeration(&self.name, &enum_attr.values); + let name = Alias::new(&self.name); + let variants: Vec = enum_attr + .values + .iter() + .map(|variant| Alias::new(variant).into_iden()) + .collect(); + col_def.enumeration(name, variants); } Type::Set(_) => { // FIXME: Unresolved type mapping diff --git a/src/postgres/discovery/executor/real.rs b/src/postgres/discovery/executor/real.rs index 84cc35d4..e3bbbe57 100644 --- a/src/postgres/discovery/executor/real.rs +++ b/src/postgres/discovery/executor/real.rs @@ -1,9 +1,7 @@ use sea_query::{PostgresQueryBuilder, SelectStatement}; +use sea_query_binder::SqlxBinder; use sqlx::{postgres::PgRow, PgPool}; -sea_query::sea_query_driver_postgres!(); -use sea_query_driver_postgres::bind_query; - use crate::debug_print; pub struct Executor { @@ -22,11 +20,10 @@ impl IntoExecutor for PgPool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(PostgresQueryBuilder); + let (sql, values) = select.build_sqlx(PostgresQueryBuilder); debug_print!("{}, {:?}", sql, values); - let query = bind_query(sqlx::query(&sql), &values); - query + sqlx::query_with(&sql, values) .fetch_all(&mut self.pool.acquire().await.unwrap()) .await .unwrap() diff --git a/src/postgres/writer/column.rs b/src/postgres/writer/column.rs index edad4c63..102ad7f0 100644 --- a/src/postgres/writer/column.rs +++ b/src/postgres/writer/column.rs @@ -1,5 +1,5 @@ use crate::postgres::def::{ColumnInfo, Type}; -use sea_query::{Alias, ColumnDef, PgInterval}; +use sea_query::{Alias, ColumnDef, DynIden, IntoIden, PgInterval}; use std::{convert::TryFrom, fmt::Write}; impl ColumnInfo { @@ -233,7 +233,13 @@ impl ColumnInfo { col_def.custom(Alias::new(s)); } Type::Enum(enum_def) => { - col_def.enumeration(&enum_def.typename, &enum_def.values); + let name = Alias::new(&enum_def.typename); + let variants: Vec = enum_def + .values + .iter() + .map(|variant| Alias::new(variant).into_iden()) + .collect(); + col_def.enumeration(name, variants); } }; col_def diff --git a/src/sqlite/executor/real.rs b/src/sqlite/executor/real.rs index a7896e78..4ec029e3 100644 --- a/src/sqlite/executor/real.rs +++ b/src/sqlite/executor/real.rs @@ -1,9 +1,7 @@ use sea_query::{SelectStatement, SqliteQueryBuilder}; +use sea_query_binder::SqlxBinder; use sqlx::{sqlite::SqliteRow, SqlitePool}; -sea_query::sea_query_driver_sqlite!(); -use sea_query_driver_sqlite::bind_query; - use crate::debug_print; pub struct Executor { @@ -22,22 +20,20 @@ impl IntoExecutor for SqlitePool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(SqliteQueryBuilder); + let (sql, values) = select.build_sqlx(SqliteQueryBuilder); debug_print!("{}, {:?}", sql, values); - let query = bind_query(sqlx::query(&sql), &values); - query + sqlx::query_with(&sql, values) .fetch_all(&mut self.pool.acquire().await.unwrap()) .await .unwrap() } pub async fn fetch_one(&self, select: SelectStatement) -> SqliteRow { - let (sql, values) = select.build(SqliteQueryBuilder); + let (sql, values) = select.build_sqlx(SqliteQueryBuilder); debug_print!("{}, {:?}", sql, values); - let query = bind_query(sqlx::query(&sql), &values); - query + sqlx::query_with(&sql, values) .fetch_one(&mut self.pool.acquire().await.unwrap()) .await .unwrap()