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

11 releases

0.3.6 Feb 14, 2023
0.3.5 Feb 10, 2023
0.3.2 Jan 11, 2023
0.3.1 Nov 18, 2022
0.1.1 Oct 19, 2022

#1076 in Development tools

Download history 4/week @ 2023-06-04 3/week @ 2023-06-11 39/week @ 2023-06-18 23/week @ 2023-06-25 38/week @ 2023-07-02 10/week @ 2023-07-09 12/week @ 2023-07-16 14/week @ 2023-07-23 31/week @ 2023-07-30 14/week @ 2023-08-06 15/week @ 2023-08-13 20/week @ 2023-08-20 19/week @ 2023-08-27 17/week @ 2023-09-03 29/week @ 2023-09-10 27/week @ 2023-09-17

92 downloads per month
Used in db-schema

MIT license

15KB
341 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

~20–34MB
~635K SLoC