sqlx-db-ssk-tester

Crates.iosqlx-db-ssk-tester
lib.rssqlx-db-ssk-tester
version0.1.1
sourcesrc
created_at2022-11-30 12:58:39.783823
updated_at2022-12-01 01:06:55.047165
description A simple tool to test sqlx with postgres , It will automatically create a database and a table for testing. and drop the database after testing.
homepagehttps://github.com/heheshang/sqlx-db-ssk-tester
repositoryhttps://github.com/heheshang/sqlx-db-ssk-tester
max_upload_size
id726152
size20,624
heheshang (heheshang)

documentation

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

README

sqlx-db-ssk-tester

This a tool to test sqlx with postgres,It only support tokio runtime at this moment.

study by tyr Chen

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 2021 ssk

Commit count: 7

cargo fmt