Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different type for params between query_typed and query_typed_raw #1192

Open
docteurklein opened this issue Nov 28, 2024 · 0 comments
Open

Comments

@docteurklein
Copy link

docteurklein commented Nov 28, 2024

Pardon the possible dumb question, but is there a good reason for the difference between:

query_typed_raw:

params: I
where
    P: BorrowToSql,
    I: IntoIterator<Item = (P, Type)>,

and query_typed:

params: &[(&(dyn ToSql + Sync), Type)],

I'm forced to have 2 different implems for passing the same values:

query_typed:

    let p1 = serde_json::to_value(&query.params);
    let p2 = serde_json::to_value(&query);
    let sql_params: Vec<(&(dyn ToSql + Sync), Type)> = vec![
        (p1.as_ref().map_err(internal_error)?, Type::JSONB),
        (p2.as_ref().map_err(internal_error)?, Type::JSONB),
    ];

    let rows: Vec<String> = tx.query_typed(&query.sql, sql_params.as_slice()).await.map_err(internal_error)?;

query_typed_raw:

    let sql_params = vec![
        (serde_json::to_value(&query.params).map_err(internal_error)?, Type::JSONB),
        (serde_json::to_value(&query).map_err(internal_error)?, Type::JSONB),
    ];

    let rows = tx.query_typed_raw(&query.sql, sql_params).await.map_err(internal_error)?;

Am I doing something wrong?
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant