Skip to content

Commit

Permalink
rename with_param to param
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Nov 19, 2024
1 parent 7fd4124 commit aa627bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Client {
}

/// Specify server side parameter for all this client's queries.
pub fn with_param(self, name: &str, value: impl Serialize) -> Result<Self, String> {
pub fn param(self, name: &str, value: impl Serialize) -> Result<Self, String> {
let mut param = String::from("");
ser::write_param(&mut param, &value)?;
Ok(self.with_option(format!("param_{name}"), param))
Expand Down
2 changes: 1 addition & 1 deletion src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Query {
/// Specify server side parameter for query.
///
/// In queries you can reference params as {name: type} e.g. {val: Int32}.
pub fn with_param(mut self, name: &str, value: impl Serialize) -> Self {
pub fn param(mut self, name: &str, value: impl Serialize) -> Self {
let mut param = String::from("");
if let Err(err) = ser::write_param(&mut param, &value) {
self.sql = SqlBuilder::Failed(format!("invalid param: {err}"));
Expand Down
10 changes: 5 additions & 5 deletions tests/it/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,36 @@ async fn fetch_one_and_optional() {
#[tokio::test]
async fn server_side_param() {
let client = prepare_database!()
.with_param("val1", 42)
.param("val1", 42)
.expect("failed to bind 42");

let result = client
.query("SELECT plus({val1: Int32}, {val2: Int32}) AS result")
.with_param("val2", 144)
.param("val2", 144)
.fetch_one::<u64>()
.await
.expect("failed to fetch u64");
assert_eq!(result, 186);

let result = client
.query("SELECT {val1: String} AS result")
.with_param("val1", "string")
.param("val1", "string")
.fetch_one::<String>()
.await
.expect("failed to fetch string");
assert_eq!(result, "string");

let result = client
.query("SELECT {val1: String} AS result")
.with_param("val1", "\x01\x02\x03\\ \"\'")
.param("val1", "\x01\x02\x03\\ \"\'")
.fetch_one::<String>()
.await
.expect("failed to fetch string");
assert_eq!(result, "\x01\x02\x03\\ \"\'");

let result = client
.query("SELECT {val1: Array(String)} AS result")
.with_param("val1", vec!["a", "bc"])
.param("val1", vec!["a", "bc"])
.fetch_one::<Vec<String>>()
.await
.expect("failed to fetch string");
Expand Down

0 comments on commit aa627bf

Please sign in to comment.