mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
make futures-util default feature + use futures in example.rs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user