#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.

14 releases

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

#998 in Development tools

Download history 4/week @ 2024-03-15 118/week @ 2024-03-22 23/week @ 2024-03-29 3/week @ 2024-04-05 5/week @ 2024-04-19 250/week @ 2024-04-26 30/week @ 2024-05-03 19/week @ 2024-05-10 21/week @ 2024-05-17 56/week @ 2024-05-24 38/week @ 2024-05-31 106/week @ 2024-06-07 127/week @ 2024-06-14 76/week @ 2024-06-21 34/week @ 2024-06-28

350 downloads per month
Used in db-schema

MIT license

16KB
351 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 TestDb 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 TestDb gets dropped, it will automatically drop the database.

#[tokio::test]
fn some_awesom_test() {
    let tdb = TestDb::new("localhost", 5432, "postgres", "postgres", "./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

~16–30MB
~435K SLoC