#sqlx #postgres #database #test

sqlx-db-tester

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

6 releases

Uses new Rust 2021

new 0.3.1 Nov 18, 2022
0.3.0 Nov 18, 2022
0.2.1 Nov 17, 2022
0.1.1 Oct 19, 2022

#757 in Development tools

Download history 62/week @ 2022-10-16 12/week @ 2022-10-23 5/week @ 2022-10-30 13/week @ 2022-11-06 94/week @ 2022-11-13

125 downloads per month

MIT license

12KB
286 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 Tyr Chen

Dependencies

~20MB
~462K SLoC