Skip to content

Commit

Permalink
sqlx-driver feature export macros, remove sqlx dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Dec 29, 2020
1 parent f1d97eb commit 3a14eff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions examples/sqlx.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 1 addition & 14 deletions src/driver/sqlx.rs
Original file line number Diff line number Diff line change
@@ -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 ) => {
{
Expand Down Expand Up @@ -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)
}

0 comments on commit 3a14eff

Please sign in to comment.