Skip to content

Commit

Permalink
docs: Add an example for sqlx (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Aug 7, 2024
1 parent 6626169 commit bfd131d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 0 additions & 11 deletions .github/actions/check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ runs:
command: fmt
args: --all -- --check

- name: Install cargo-audit
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-audit

- name: Audit dependencies
uses: actions-rs/cargo@v1
with:
command: audit

- name: Clippy
uses: actions-rs/cargo@v1
with:
Expand Down
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 bfd131d

Please sign in to comment.