From 3a14effc1946142f8b11eb31986dfa6815ee1504 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 29 Dec 2020 21:49:57 +0800 Subject: [PATCH] sqlx-driver feature export macros, remove sqlx dependencies --- Cargo.toml | 3 +-- examples/sqlx.rs | 14 ++++++++++++-- src/driver/sqlx.rs | 15 +-------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 059ee9cd4..7db006f21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,13 @@ name = "sea_query" [dependencies] serde_json = "1.0" -sqlx = { optional = true, version = "0.4.0", default-features = false, features = [ "runtime-async-std-native-tls", "macros", "any", "mysql", "postgres", "sqlite", "tls", "migrate", "decimal" ] } [dev-dependencies] async-std = "1.8" sqlx = { version = "0.4.0", default-features = false, features = [ "runtime-async-std-native-tls", "macros", "any", "mysql", "postgres", "sqlite", "tls", "migrate", "decimal" ] } [features] -sqlx-driver = ["sqlx"] +sqlx-driver = [] [[example]] name = "sqlx" diff --git a/examples/sqlx.rs b/examples/sqlx.rs index a513bd3c3..fb94841bf 100644 --- a/examples/sqlx.rs +++ b/examples/sqlx.rs @@ -1,9 +1,11 @@ use std::fmt; use async_std::task; use serde_json::json; -use sqlx::AnyPool; +use sqlx::{Any, AnyPool, any::AnyArguments}; use sea_query::*; -use sea_query::driver::sqlx::{bind_query, bind_query_as}; + +type SqlxQuery<'a> = sqlx::query::Query<'a, Any, AnyArguments<'a>>; +type SqlxQueryAs<'a, T> = sqlx::query::QueryAs<'a, Any, T, AnyArguments<'a>>; fn main() { // mysql or postgresql @@ -85,6 +87,14 @@ fn main() { } } +pub fn bind_query<'a>(query: SqlxQuery<'a>, params: &'a [Value]) -> SqlxQuery<'a> { + bind_params!(query, params) +} + +pub fn bind_query_as<'a, T>(query: SqlxQueryAs<'a, T>, params: &'a [Value]) -> SqlxQueryAs<'a, T> { + bind_params!(query, params) +} + enum Character { Table, Id, diff --git a/src/driver/sqlx.rs b/src/driver/sqlx.rs index 8a5d47728..d31ebf839 100644 --- a/src/driver/sqlx.rs +++ b/src/driver/sqlx.rs @@ -1,9 +1,4 @@ -use sqlx::{Any, any::AnyArguments}; -use crate::*; - -type SqlxQuery<'a> = sqlx::query::Query<'a, Any, AnyArguments<'a>>; -type SqlxQueryAs<'a, T> = sqlx::query::QueryAs<'a, Any, T, AnyArguments<'a>>; - +#[macro_export] macro_rules! bind_params { ( $query:expr, $params:expr ) => { { @@ -31,12 +26,4 @@ macro_rules! bind_params { query } }; -} - -pub fn bind_query<'a>(query: SqlxQuery<'a>, params: &'a [Value]) -> SqlxQuery<'a> { - bind_params!(query, params) -} - -pub fn bind_query_as<'a, T>(query: SqlxQueryAs<'a, T>, params: &'a [Value]) -> SqlxQueryAs<'a, T> { - bind_params!(query, params) } \ No newline at end of file