mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 18:40:24 +00:00
Add query_unchecked and query_file_unchecked macros
This commit is contained in:
@@ -127,14 +127,28 @@ macro_rules! async_macro (
|
||||
#[allow(unused_variables)]
|
||||
pub fn query(input: TokenStream) -> TokenStream {
|
||||
#[allow(unused_variables)]
|
||||
async_macro!(db, input: QueryMacroInput => expand_query(input, db))
|
||||
async_macro!(db, input: QueryMacroInput => expand_query(input, db, true))
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
#[allow(unused_variables)]
|
||||
pub fn query_unchecked(input: TokenStream) -> TokenStream {
|
||||
#[allow(unused_variables)]
|
||||
async_macro!(db, input: QueryMacroInput => expand_query(input, db, false))
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
#[allow(unused_variables)]
|
||||
pub fn query_file(input: TokenStream) -> TokenStream {
|
||||
#[allow(unused_variables)]
|
||||
async_macro!(db, input: QueryMacroInput => expand_query_file(input, db))
|
||||
async_macro!(db, input: QueryMacroInput => expand_query_file(input, db, true))
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
#[allow(unused_variables)]
|
||||
pub fn query_file_unchecked(input: TokenStream) -> TokenStream {
|
||||
#[allow(unused_variables)]
|
||||
async_macro!(db, input: QueryMacroInput => expand_query_file(input, db, false))
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
|
||||
@@ -19,12 +19,13 @@ mod query;
|
||||
pub async fn expand_query_file<C: Connection>(
|
||||
input: QueryMacroInput,
|
||||
conn: C,
|
||||
checked: bool,
|
||||
) -> crate::Result<TokenStream>
|
||||
where
|
||||
C::Database: DatabaseExt + Sized,
|
||||
<C::Database as Database>::TypeInfo: Display,
|
||||
{
|
||||
expand_query(input.expand_file_src().await?, conn).await
|
||||
expand_query(input.expand_file_src().await?, conn, checked).await
|
||||
}
|
||||
|
||||
pub async fn expand_query_as<C: Connection>(
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::database::DatabaseExt;
|
||||
pub async fn expand_query<C: Connection>(
|
||||
input: QueryMacroInput,
|
||||
mut conn: C,
|
||||
checked: bool,
|
||||
) -> crate::Result<TokenStream>
|
||||
where
|
||||
C::Database: DatabaseExt + Sized,
|
||||
@@ -23,7 +24,7 @@ where
|
||||
let describe = input.describe_validate(&mut conn).await?;
|
||||
let sql = &input.source;
|
||||
|
||||
let args = args::quote_args(&input, &describe, true)?;
|
||||
let args = args::quote_args(&input, &describe, checked)?;
|
||||
|
||||
let arg_names = &input.arg_names;
|
||||
let db_path = <C::Database as DatabaseExt>::db_path();
|
||||
@@ -57,8 +58,13 @@ where
|
||||
.collect::<TokenStream>();
|
||||
|
||||
let query_args = format_ident!("query_args");
|
||||
let output =
|
||||
output::quote_query_as::<C::Database>(sql, &record_type, &query_args, &columns, true);
|
||||
let output = output::quote_query_as::<C::Database>(
|
||||
sql,
|
||||
&record_type,
|
||||
&query_args,
|
||||
if checked { &columns } else { &[] },
|
||||
checked,
|
||||
);
|
||||
|
||||
Ok(quote! {
|
||||
macro_rules! macro_result {
|
||||
|
||||
Reference in New Issue
Block a user