Merge remote-tracking branch 'origin/main' into zmd

This commit is contained in:
Nathan Sobo 2023-05-24 11:04:07 -06:00
commit 747322a02d
107 changed files with 5048 additions and 3991 deletions

View file

@ -27,7 +27,7 @@ impl StaticColumnCount for bool {}
impl Bind for bool {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
statement
.bind(self.then_some(1).unwrap_or(0), start_index)
.bind(&self.then_some(1).unwrap_or(0), start_index)
.with_context(|| format!("Failed to bind bool at index {start_index}"))
}
}

View file

@ -236,7 +236,7 @@ impl<'a> Statement<'a> {
Ok(str::from_utf8(slice)?)
}
pub fn bind<T: Bind>(&self, value: T, index: i32) -> Result<i32> {
pub fn bind<T: Bind>(&self, value: &T, index: i32) -> Result<i32> {
debug_assert!(index > 0);
Ok(value.bind(self, index)?)
}
@ -258,7 +258,7 @@ impl<'a> Statement<'a> {
}
}
pub fn with_bindings(&mut self, bindings: impl Bind) -> Result<&mut Self> {
pub fn with_bindings(&mut self, bindings: &impl Bind) -> Result<&mut Self> {
self.bind(bindings, 1)?;
Ok(self)
}
@ -464,7 +464,7 @@ mod test {
connection
.exec(indoc! {"
CREATE TABLE texts (
text TEXT
text TEXT
)"})
.unwrap()()
.unwrap();

View file

@ -29,7 +29,7 @@ impl Connection {
query: &str,
) -> Result<impl 'a + FnMut(B) -> Result<()>> {
let mut statement = Statement::prepare(self, query)?;
Ok(move |bindings| statement.with_bindings(bindings)?.exec())
Ok(move |bindings| statement.with_bindings(&bindings)?.exec())
}
/// Prepare a statement which has no bindings and returns a `Vec<C>`.
@ -55,7 +55,7 @@ impl Connection {
query: &str,
) -> Result<impl 'a + FnMut(B) -> Result<Vec<C>>> {
let mut statement = Statement::prepare(self, query)?;
Ok(move |bindings| statement.with_bindings(bindings)?.rows::<C>())
Ok(move |bindings| statement.with_bindings(&bindings)?.rows::<C>())
}
/// Prepare a statement that selects a single row from the database.
@ -87,7 +87,7 @@ impl Connection {
let mut statement = Statement::prepare(self, query)?;
Ok(move |bindings| {
statement
.with_bindings(bindings)
.with_bindings(&bindings)
.context("Bindings failed")?
.maybe_row::<C>()
.context("Maybe row failed")