mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 00:54:19 +01:00
Revert "Merge 'Rust binding improvements' from Pedro Muniz"
This reverts commitbd60cd214c, reversing changes made to74e48a3a8fbecause it makes limbo_stress hang.
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
#![cfg(feature = "futures")]
|
||||
|
||||
use futures_util::stream::TryStreamExt;
|
||||
use turso::Builder;
|
||||
|
||||
#[tokio::main]
|
||||
@@ -9,15 +6,8 @@ async fn main() {
|
||||
|
||||
let conn = db.connect().unwrap();
|
||||
|
||||
// `query` and other methods, only parse the first query given.
|
||||
let mut rows = conn.query("select 1; select 1;", ()).await.unwrap();
|
||||
// Iterate over the rows with the Stream iterator syntax
|
||||
while let Some(row) = rows.try_next().await.unwrap() {
|
||||
let val = row.get_value(0).unwrap();
|
||||
println!("{:?}", val);
|
||||
}
|
||||
conn.query("select 1; select 1;", ()).await.unwrap();
|
||||
|
||||
// Contrary to `prepare` and `query`, `execute` is not lazy and will execute the query to completion
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS users (email TEXT)", ())
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -42,20 +32,9 @@ async fn main() {
|
||||
|
||||
let mut rows = stmt.query(["foo@example.com"]).await.unwrap();
|
||||
|
||||
while let Some(row) = rows.try_next().await.unwrap() {
|
||||
let value = row.get_value(0).unwrap();
|
||||
println!("Row: {:?}", value);
|
||||
}
|
||||
let row = rows.next().await.unwrap().unwrap();
|
||||
|
||||
let rows = stmt.query(["foo@example.com"]).await.unwrap();
|
||||
let value = row.get_value(0).unwrap();
|
||||
|
||||
// As `Rows` implement streams you can easily map over it and apply other transformations you see fit
|
||||
println!("Using Stream map");
|
||||
rows.map_ok(|row| row.get_value(0).unwrap())
|
||||
.try_for_each(|val| {
|
||||
println!("Row: {:?}", val.as_text().unwrap());
|
||||
futures_util::future::ready(Ok(()))
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Row: {:?}", value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user