#sqlx #postgresql #fb #testing

sqlx-db-tester-fb

自用,一个用于测试 sqlx 和 postgres 的简单工具。它在测试结束后会自动创建和删除数据库。

1 个不稳定版本

0.1.0 2023年5月11日

#2421 in 开发工具

MIT 许可协议

9KB
140 代码行

sqlx-db-tester-fb

这是一个用于测试 sqlx 和 postgres 的工具。目前它仅支持 tokio 运行时。

如何使用

您应该在测试中首先创建一个 TestDb 数据结构。它会自动为您创建数据库和连接池。然后您可以从其中获取连接字符串或连接池,用于您自己的代码。当 TestDb 被丢弃时,它将自动删除数据库。

#[tokio::test]
fn some_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
}

许可协议

本项目遵循 MIT 许可协议。

有关详细信息,请参阅 LICENSE

版权所有 2023 Fly Bear

依赖项

~20–32MB
~583K SLoC