make futures-util default feature + use futures in example.rs

This commit is contained in:
pedrocarlo
2025-06-30 12:48:59 -03:00
parent a1fe46779d
commit e08748e07e
4 changed files with 30 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
#[cfg(feature = "futures")]
use futures_util::stream::StreamExt;
#![cfg(feature = "futures")]
use futures_util::stream::TryStreamExt;
use turso::Builder;
#[tokio::main]
@@ -8,8 +9,15 @@ async fn main() {
let conn = db.connect().unwrap();
conn.query("select 1; select 1;", ()).await.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);
}
// 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();
@@ -34,9 +42,8 @@ async fn main() {
let mut rows = stmt.query(["foo@example.com"]).await.unwrap();
let row = rows.next().await.unwrap().unwrap();
let value = row.get_value(0).unwrap();
println!("Row: {:?}", value);
while let Some(row) = rows.try_next().await.unwrap() {
let value = row.get_value(0).unwrap();
println!("Row: {:?}", value);
}
}