Last active
April 3, 2020 06:53
-
-
Save espeon/ab4fae3d6b93351b468fac5b7af7aaad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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