mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 07:21:08 +00:00
don't typecheck parameters on MySQL
This commit is contained in:
parent
b85618e5f8
commit
5c7661985e
@ -1,8 +1,16 @@
|
||||
use sqlx::Backend;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum ParamChecking {
|
||||
Strong,
|
||||
Weak
|
||||
}
|
||||
|
||||
pub trait BackendExt: Backend {
|
||||
const BACKEND_PATH: &'static str;
|
||||
|
||||
const PARAM_CHECKING: ParamChecking;
|
||||
|
||||
fn quotable_path() -> syn::Path {
|
||||
syn::parse_str(Self::BACKEND_PATH).unwrap()
|
||||
}
|
||||
@ -13,9 +21,10 @@ pub trait BackendExt: Backend {
|
||||
}
|
||||
|
||||
macro_rules! impl_backend_ext {
|
||||
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $input:ty)?),*$(,)? }) => {
|
||||
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $input:ty)?),*$(,)? }, ParamChecking::$param_checking:ident) => {
|
||||
impl $crate::backend::BackendExt for $backend {
|
||||
const BACKEND_PATH: &'static str = stringify!($backend);
|
||||
const PARAM_CHECKING: $crate::backend::ParamChecking = $crate::backend::ParamChecking::$param_checking;
|
||||
|
||||
fn param_type_for_id(id: &Self::TypeId) -> Option<&'static str> {
|
||||
use sqlx::types::TypeMetadata;
|
||||
|
@ -7,5 +7,6 @@ impl_backend_ext! {
|
||||
i64,
|
||||
f32,
|
||||
f64
|
||||
}
|
||||
},
|
||||
ParamChecking::Weak
|
||||
}
|
||||
|
@ -19,5 +19,6 @@ impl_backend_ext! {
|
||||
sqlx::types::chrono::NaiveDateTime,
|
||||
#[cfg(feature = "chrono")]
|
||||
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc> | sqlx::types::chrono::DateTime<_>,
|
||||
}
|
||||
},
|
||||
ParamChecking::Strong
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use syn::{
|
||||
use quote::{format_ident, quote, quote_spanned, ToTokens};
|
||||
use sqlx::{Connection, HasTypeMetadata};
|
||||
|
||||
use crate::backend::BackendExt;
|
||||
use crate::backend::{BackendExt, ParamChecking};
|
||||
|
||||
pub struct MacroInput {
|
||||
sql: String,
|
||||
@ -107,7 +107,7 @@ pub async fn process_sql<C: Connection>(
|
||||
(record_type.to_token_stream(), generate_record_def(&describe, &record_type)?)
|
||||
};
|
||||
|
||||
let params = if input.args.is_empty() {
|
||||
let params = if <C::Backend as BackendExt>::PARAM_CHECKING == ParamChecking::Weak || input.args.is_empty() {
|
||||
quote! {
|
||||
let params = ();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user