Crates.io | sqlx-tester |
lib.rs | sqlx-tester |
version | 0.1.0 |
source | src |
created_at | 2022-12-14 08:27:53.741583 |
updated_at | 2022-12-14 08:27:53.741583 |
description | learn rust from the tyrchen |
homepage | https://github.com/dongjiahong/sqlx-tester |
repository | https://github.com/dongjiahong/sqlx-tester |
max_upload_size | |
id | 736429 |
size | 19,200 |
This a tool to test sqlx with postgres. It only supports tokio runtime at this moment.
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!
This project is distributed under the terms of MIT.
See LICENSE for details.