xsqlx-db-tester

Crates.ioxsqlx-db-tester
lib.rsxsqlx-db-tester
version0.1.3
sourcesrc
created_at2023-06-01 19:07:38.422769
updated_at2023-06-02 08:59:28.250382
descriptionA simple tool to test sqlx database, it automatically create and drop database when the test create and drop.
homepagehttps://github.com/laizhenxing/xsqlx-db-tester
repositoryhttps://github.com/laizhenxing/xsqlx-db-tester
max_upload_size
id880034
size20,671
xingxiaoli (laizhenxing)

documentation

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

README

Source

This project learns from: https://github.com/tyrchen/sqlx-db-tester/tree/master

xsqlx-db-tester

This a tool test sqlx with postgres. It only support tokio runtime in this moment.

How to use it

You should first create TestDB data structure in your tests. It will automcatically create a database and a connection pool for you. Then you could get the connection string or connection pool from it to use on your own code. When TestDB gets drop, it will automcatically drop the database.

#[tokio::test]
async fn some_test() {
    let tdb = TestDB::new("postgers://postgrses:postgres@localhost:5432", "./migrations");
    let pool = tdb.get_pool().await;
    // do you test logic

    // the code finish in this test, tdb will drop the database which it create.
}

Have fun with this crate!

License

This project is distributed under the terms of MIT license.

Commit count: 12

cargo fmt