mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-04-14 16:30:16 +00:00
feat(mssql): add macro support
This commit is contained in:
@@ -97,3 +97,6 @@ mod mysql;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
mod sqlite;
|
||||
|
||||
#[cfg(feature = "mssql")]
|
||||
mod mssql;
|
||||
|
||||
17
sqlx-macros/src/database/mssql.rs
Normal file
17
sqlx-macros/src/database/mssql.rs
Normal 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"
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user