Skip to content

Instantly share code, notes, and snippets.

@espeon
Last active April 3, 2020 06:53
Show Gist options
  • Select an option

  • Save espeon/ab4fae3d6b93351b468fac5b7af7aaad to your computer and use it in GitHub Desktop.

Select an option

Save espeon/ab4fae3d6b93351b468fac5b7af7aaad to your computer and use it in GitHub Desktop.
use sqlx::SqlitePool;
#[tokio::main]
async fn main() {
let pool = SqlitePool::builder()
.max_size(1)
.build("sqlite3://todos.sqlite3")
.await
.expect("Failed to create DB pool");
println!("{:#?}", &pool);
let list = list_todos(&pool).await;
println!("{:#?}", &list);
}
async fn list_todos(pool: &SqlitePool) -> anyhow::Result<()> {
let recs = sqlx::query!(
r#"
SELECT id, description, done
FROM todos
ORDER BY id
"#
)
.fetch_all(pool)
.await?;
for rec in recs {
println!(
"- [{}] {}: {}",
if rec.done { "x" } else { " " },
rec.id,
&rec.description,
);
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment