-
Notifications
You must be signed in to change notification settings - Fork 86
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
with_param #159
base: main
Are you sure you want to change the base?
with_param #159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use hyper::{header::CONTENT_LENGTH, Method, Request}; | ||
use serde::Deserialize; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::Display; | ||
use url::Url; | ||
|
||
|
@@ -10,7 +10,7 @@ use crate::{ | |
request_body::RequestBody, | ||
response::Response, | ||
row::Row, | ||
sql::{Bind, SqlBuilder}, | ||
sql::{ser, Bind, SqlBuilder}, | ||
Client, | ||
}; | ||
|
||
|
@@ -195,6 +195,12 @@ impl Query { | |
self.client.add_option(name, value); | ||
self | ||
} | ||
|
||
pub fn with_param(self, name: &str, value: impl Serialize) -> Result<Self, String> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still trying to figure out the naming here. This one is consistent with For instance, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So, I suggest delayed errors in the same way as in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method must be well documented. Also, we should specify the difference between
loyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut param = String::from(""); | ||
ser::write_param(&mut param, &value)?; | ||
Ok(self.with_option(format!("param_{name}"), param)) | ||
} | ||
} | ||
|
||
/// A cursor that emits rows. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of
Client::with_param
? Parameters are specific for queries, not the whole clientThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, but if someone wants to share parameter between queries queries they can put it on the client
For example, in a multi tenant app, tenantid could be put as a parameter in the function creating client