Skip to content

Commit 5c76619

Browse files
abonandermehcode
authored andcommitted
don't typecheck parameters on MySQL
1 parent b85618e commit 5c76619

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

sqlx-macros/src/backend/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
use sqlx::Backend;
22

3+
#[derive(PartialEq, Eq)]
4+
pub enum ParamChecking {
5+
Strong,
6+
Weak
7+
}
8+
39
pub trait BackendExt: Backend {
410
const BACKEND_PATH: &'static str;
511

12+
const PARAM_CHECKING: ParamChecking;
13+
614
fn quotable_path() -> syn::Path {
715
syn::parse_str(Self::BACKEND_PATH).unwrap()
816
}
@@ -13,9 +21,10 @@ pub trait BackendExt: Backend {
1321
}
1422

1523
macro_rules! impl_backend_ext {
16-
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $input:ty)?),*$(,)? }) => {
24+
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $input:ty)?),*$(,)? }, ParamChecking::$param_checking:ident) => {
1725
impl $crate::backend::BackendExt for $backend {
1826
const BACKEND_PATH: &'static str = stringify!($backend);
27+
const PARAM_CHECKING: $crate::backend::ParamChecking = $crate::backend::ParamChecking::$param_checking;
1928

2029
fn param_type_for_id(id: &Self::TypeId) -> Option<&'static str> {
2130
use sqlx::types::TypeMetadata;

sqlx-macros/src/backend/mysql.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ impl_backend_ext! {
77
i64,
88
f32,
99
f64
10-
}
10+
},
11+
ParamChecking::Weak
1112
}

sqlx-macros/src/backend/postgres.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ impl_backend_ext! {
1919
sqlx::types::chrono::NaiveDateTime,
2020
#[cfg(feature = "chrono")]
2121
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc> | sqlx::types::chrono::DateTime<_>,
22-
}
22+
},
23+
ParamChecking::Strong
2324
}

sqlx-macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syn::{
1212
use quote::{format_ident, quote, quote_spanned, ToTokens};
1313
use sqlx::{Connection, HasTypeMetadata};
1414

15-
use crate::backend::BackendExt;
15+
use crate::backend::{BackendExt, ParamChecking};
1616

1717
pub struct MacroInput {
1818
sql: String,
@@ -107,7 +107,7 @@ pub async fn process_sql<C: Connection>(
107107
(record_type.to_token_stream(), generate_record_def(&describe, &record_type)?)
108108
};
109109

110-
let params = if input.args.is_empty() {
110+
let params = if <C::Backend as BackendExt>::PARAM_CHECKING == ParamChecking::Weak || input.args.is_empty() {
111111
quote! {
112112
let params = ();
113113
}

0 commit comments

Comments
 (0)