mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 21:44:21 +01:00
Merge 'bindings/rust: Named params' from Andika Tanuwijaya
Closes #1876
This commit is contained in:
@@ -229,7 +229,13 @@ impl Statement {
|
||||
stmt.bind_at(NonZero::new(i + 1).unwrap(), value.into());
|
||||
}
|
||||
}
|
||||
params::Params::Named(_items) => todo!(),
|
||||
params::Params::Named(values) => {
|
||||
for (name, value) in values.into_iter() {
|
||||
let mut stmt = self.inner.lock().unwrap();
|
||||
let i = stmt.parameters().index(name).unwrap();
|
||||
stmt.bind_at(i, value.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
let rows = Rows {
|
||||
@@ -253,7 +259,13 @@ impl Statement {
|
||||
stmt.bind_at(NonZero::new(i + 1).unwrap(), value.into());
|
||||
}
|
||||
}
|
||||
params::Params::Named(_items) => todo!(),
|
||||
params::Params::Named(values) => {
|
||||
for (name, value) in values.into_iter() {
|
||||
let mut stmt = self.inner.lock().unwrap();
|
||||
let i = stmt.parameters().index(name).unwrap();
|
||||
stmt.bind_at(i, value.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
loop {
|
||||
let mut stmt = self.inner.lock().unwrap();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use limbo::Builder;
|
||||
use limbo::{Builder, Value};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_rows_next() {
|
||||
@@ -14,6 +14,24 @@ async fn test_rows_next() {
|
||||
conn.execute("INSERT INTO test (x) VALUES (2)", ())
|
||||
.await
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO test (x) VALUES (:x)",
|
||||
vec![(":x".to_string(), Value::Integer(3))],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO test (x) VALUES (@x)",
|
||||
vec![("@x".to_string(), Value::Integer(4))],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO test (x) VALUES ($x)",
|
||||
vec![("$x".to_string(), Value::Integer(5))],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut res = conn.query("SELECT * FROM test", ()).await.unwrap();
|
||||
assert_eq!(
|
||||
res.next().await.unwrap().unwrap().get_value(0).unwrap(),
|
||||
@@ -23,5 +41,17 @@ async fn test_rows_next() {
|
||||
res.next().await.unwrap().unwrap().get_value(0).unwrap(),
|
||||
2.into()
|
||||
);
|
||||
assert_eq!(
|
||||
res.next().await.unwrap().unwrap().get_value(0).unwrap(),
|
||||
3.into()
|
||||
);
|
||||
assert_eq!(
|
||||
res.next().await.unwrap().unwrap().get_value(0).unwrap(),
|
||||
4.into()
|
||||
);
|
||||
assert_eq!(
|
||||
res.next().await.unwrap().unwrap().get_value(0).unwrap(),
|
||||
5.into()
|
||||
);
|
||||
assert!(res.next().await.unwrap().is_none());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user