fix: tweak sqlx-core usage in macros after the latest massive refactor

This commit is contained in:
Ryan Leckey 2020-05-30 17:56:19 -07:00
parent e08f05b879
commit e8aa127c55
No known key found for this signature in database
GPG Key ID: BBDFC5595030E7D3
5 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ pub struct QueryData<DB: Database> {
impl<DB: Database> QueryData<DB> {
pub async fn from_db(
conn: &mut impl Executor<Database = DB>,
conn: impl Executor<'_, Database = DB>,
query: &str,
) -> crate::Result<Self> {
Ok(QueryData {

View File

@ -39,6 +39,7 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result<TokenStream> {
// if `dotenv` wasn't initialized by the above we make sure to do it here
match dotenv::var("DATABASE_URL").ok() {
Some(db_url) => expand_from_db(input, &db_url),
#[cfg(feature = "offline")]
None => {
let data_file_path = std::path::Path::new(&manifest_dir).join("sqlx-data.json");
@ -53,11 +54,13 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result<TokenStream> {
)
}
}
#[cfg(not(feature = "offline"))]
None => Err("`DATABASE_URL` must be set to use query macros".into()),
}
}
#[allow(unused_variables)]
fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenStream> {
let db_url = Url::parse(db_url)?;
match db_url.scheme() {
@ -156,12 +159,12 @@ where
Describe<DB>: DescribeExt,
{
// validate at the minimum that our args match the query's input parameters
if input.arg_names.len() != data.describe.param_types.len() {
if input.arg_names.len() != data.describe.params.len() {
return Err(syn::Error::new(
Span::call_site(),
format!(
"expected {} parameters, got {}",
data.describe.param_types.len(),
data.describe.params.len(),
input.arg_names.len()
),
)
@ -172,7 +175,7 @@ where
let query_args = format_ident!("query_args");
let output = if data.describe.result_columns.is_empty() {
let output = if data.describe.columns.is_empty() {
let db_path = DB::db_path();
let sql = &input.src;

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@