feat(mssql): add macro support

This commit is contained in:
Ryan Leckey
2020-06-07 16:29:46 -07:00
parent a0ccc135aa
commit 6497d67b6a
7 changed files with 125 additions and 94 deletions

View File

@@ -30,6 +30,7 @@ offline = ["sqlx-core/offline", "serde", "serde_json", "hex", "sha2"]
mysql = [ "sqlx-core/mysql" ]
postgres = [ "sqlx-core/postgres" ]
sqlite = [ "sqlx-core/sqlite" ]
mssql = [ "sqlx-core/mssql" ]
# type
bigdecimal = [ "sqlx-core/bigdecimal" ]
@@ -40,18 +41,18 @@ uuid = [ "sqlx-core/uuid" ]
json = [ "sqlx-core/json", "serde_json" ]
[dependencies]
async-std = { version = "1.5.0", default-features = false, optional = true }
tokio = { version = "0.2.13", default-features = false, features = [ "rt-threaded" ], optional = true }
async-std = { version = "1.6.0", default-features = false, optional = true }
tokio = { version = "0.2.21", default-features = false, features = [ "rt-threaded" ], optional = true }
dotenv = { version = "0.15.0", default-features = false }
futures = { version = "0.3.4", default-features = false, features = [ "executor" ] }
hex = { version = "0.4.2", optional = true }
heck = "0.3"
heck = "0.3.1"
proc-macro2 = { version = "1.0.9", default-features = false }
sqlx-core = { version = "0.4.0-pre", default-features = false, path = "../sqlx-core" }
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", features = [ "preserve_order" ], optional = true }
sha2 = { version = "0.8.1", optional = true }
syn = { version = "1.0.16", default-features = false, features = [ "full" ] }
quote = { version = "1.0.2", default-features = false }
serde = { version = "1.0.111", optional = true }
serde_json = { version = "1.0.30", features = [ "preserve_order" ], optional = true }
sha2 = { version = "0.8.2", optional = true }
syn = { version = "1.0.30", default-features = false, features = [ "full" ] }
quote = { version = "1.0.6", default-features = false }
url = { version = "2.1.1", default-features = false }
once_cell = { version = "1.3", features = ["std"], optional = true }

View File

@@ -97,3 +97,6 @@ mod mysql;
#[cfg(feature = "sqlite")]
mod sqlite;
#[cfg(feature = "mssql")]
mod mssql;

View File

@@ -0,0 +1,17 @@
use sqlx_core as sqlx;
impl_database_ext! {
sqlx::mssql::Mssql {
i8,
i16,
i32,
i64,
f32,
f64,
String,
},
ParamChecking::Weak,
feature-types: _info => None,
row = sqlx::mssql::MssqlRow,
name = "MSSQL"
}

View File

@@ -16,13 +16,10 @@ use crate::query::data::QueryData;
use crate::query::input::RecordType;
use crate::runtime::block_on;
// pub use query::expand_query;
mod args;
mod data;
mod input;
mod output;
// mod query;
pub fn expand_input(input: QueryMacroInput) -> crate::Result<TokenStream> {
let manifest_dir =
@@ -76,8 +73,23 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
expand_with_data(input, data)
},
#[cfg(not(feature = "postgres"))]
"postgres" | "postgresql" => Err(format!("database URL has the scheme of a PostgreSQL database but the `postgres` feature is not enabled").into()),
#[cfg(feature = "mssql")]
"mssql" | "sqlserver" => {
let data = block_on(async {
let mut conn = sqlx_core::mssql::MssqlConnection::connect(db_url.as_str()).await?;
QueryData::from_db(&mut conn, &input.src).await
})?;
expand_with_data(input, data)
},
#[cfg(not(feature = "mssql"))]
"mssql" | "sqlserver" => Err(format!("database URL has the scheme of a MSSQL database but the `mssql` feature is not enabled").into()),
#[cfg(feature = "mysql")]
"mysql" | "mariadb" => {
let data = block_on(async {
@@ -87,8 +99,10 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
expand_with_data(input, data)
},
#[cfg(not(feature = "mysql"))]
"mysql" | "mariadb" => Err(format!("database URL has the scheme of a MySQL/MariaDB database but the `mysql` feature is not enabled").into()),
#[cfg(feature = "sqlite")]
"sqlite" => {
let data = block_on(async {
@@ -98,8 +112,10 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
expand_with_data(input, data)
},
#[cfg(not(feature = "sqlite"))]
"sqlite" => Err(format!("database URL has the scheme of a SQLite database but the `sqlite` feature is not enabled").into()),
scheme => Err(format!("unknown database URL scheme {:?}", scheme).into())
}
}