#postgresql #sqlx #connection-pool #testing #database

sqlx-db-tester

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

15 releases

0.5.0 Sep 25, 2024
0.4.2 Apr 29, 2024
0.4.0 Dec 18, 2023
0.3.6 Feb 14, 2023
0.1.1 Oct 19, 2022

#524 in Development tools

Download history 43/week @ 2024-07-01 50/week @ 2024-07-08 131/week @ 2024-07-15 103/week @ 2024-07-22 158/week @ 2024-07-29 108/week @ 2024-08-05 128/week @ 2024-08-12 102/week @ 2024-08-19 151/week @ 2024-08-26 115/week @ 2024-09-02 112/week @ 2024-09-09 106/week @ 2024-09-16 306/week @ 2024-09-23 182/week @ 2024-09-30 62/week @ 2024-10-07 126/week @ 2024-10-14

690 downloads per month
Used in db-schema

MIT license

17KB
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

~15–27MB
~413K SLoC