#postgresql #sqlx #database-testing

sqlx-db-tester

A simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test.

16 unstable releases (5 breaking)

Uses new Rust 2024

0.6.0 Mar 30, 2025
0.5.0 Sep 25, 2024
0.4.2 Apr 29, 2024
0.4.0 Dec 18, 2023
0.3.1 Nov 18, 2022

#294 in Database interfaces

Download history 83/week @ 2024-12-22 40/week @ 2024-12-29 267/week @ 2025-01-05 359/week @ 2025-01-12 351/week @ 2025-01-19 117/week @ 2025-01-26 269/week @ 2025-02-02 315/week @ 2025-02-09 173/week @ 2025-02-16 370/week @ 2025-02-23 193/week @ 2025-03-02 298/week @ 2025-03-09 335/week @ 2025-03-16 329/week @ 2025-03-23 281/week @ 2025-03-30 196/week @ 2025-04-06

1,207 downloads per month
Used in 2 crates

MIT license

27KB
381 lines

sqlx-db-tester

This a tool to test sqlx with postgres. It only supports tokio runtime at this moment.

How to use it

You should first create a TestPg data structure in your tests. It will automatically create a database and a connection pool for you. You could then get the connection string or connection pool from it to use in your own code. When TestPg gets dropped, it will automatically drop the database.

#[tokio::test]
fn some_awesom_test() {
    let tdb = TestPg::new(
            "postgres://postgres:postgres@localhost:5432".to_string(),
            std::path::Path::new("./migrations"),
        )
    let pool = tdb.get_pool().await;
    // do something with the pool

    // when tdb gets dropped, the database will be dropped
}

Have fun with this crate!

License

This project is distributed under the terms of MIT.

See LICENSE for details.

Copyright 2022-2024 Tyr Chen

Dependencies

~17–29MB
~456K SLoC