Skip to content

Commit

Permalink
docs: Add an example for sqlx
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Aug 7, 2024
1 parent 6626169 commit d9c9426
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tokio = { version = "1", features = ["time"] }
[dev-dependencies]
anyhow = "1"
reqwest = "0.12"
tokio = { version = "1", features = ["time", "rt", "macros", "sync"] }
tokio = { version = "1", features = ["time", "rt", "macros", "sync", "rt-multi-thread"] }
sqlx = { version = "0.8.0", features = ["runtime-tokio", "sqlite"] }
20 changes: 20 additions & 0 deletions examples/sqlx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;
use sqlx::sqlite::SqlitePoolOptions;

#[tokio::main]
async fn main() -> Result<()> {
let pool = SqlitePoolOptions::new()
.max_connections(5)
.connect("sqlite::memory:")
.await?;

let row: (i64,) = (|| sqlx::query_as("SELECT $1").bind(150_i64).fetch_one(&pool))
.retry(&ExponentialBuilder::default())
.await?;

assert_eq!(row.0, 150);

Ok(())
}

0 comments on commit d9c9426

Please sign in to comment.