sqlx-db-tester

Crates.iosqlx-db-tester
lib.rssqlx-db-tester
version0.5.0
sourcesrc
created_at2022-10-16 06:30:06.882844
updated_at2024-09-25 05:06:52.46672
descriptionA simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test.
homepagehttps://github.com/tyrchen/sqlx-db-tester
repositoryhttps://github.com/tyrchen/sqlx-db-tester
max_upload_size
id689342
size43,074
Tyr Chen (tyrchen)

documentation

https://docs.rs/sqlx-db-tester

README

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

Commit count: 38

cargo fmt