Crates.io | sqlx_mock |
lib.rs | sqlx_mock |
version | 0.1.2 |
source | src |
created_at | 2022-12-08 13:27:42.781959 |
updated_at | 2022-12-12 12:38:51.872368 |
description | A simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test. |
homepage | https://github.com/wangxinyang/sqlx-mock |
repository | https://github.com/wangxinyang/sqlx-mock |
max_upload_size | |
id | 732580 |
size | 51,650 |
This a tool to test sqlx with postgres. It only supports tokio runtime at this moment.
You should first create a TestPostgres
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 TestPostgres
gets dropped, it will automatically drop the database.
#[tokio::test]
fn some_awesom_test() {
let tdb = TestPostgres::new("postgres://tosei:tosei@localhost:5432".into(), 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!
This project is distributed under the terms of MIT.
See LICENSE for details.
Copyright 2022 Xinyang Wang