52 releases (22 breaking)
new 0.23.0 | Nov 17, 2024 |
---|---|
0.21.0 | Jul 1, 2024 |
0.19.1 | Jan 4, 2024 |
0.19.0 | Nov 14, 2023 |
0.1.0 | Dec 10, 2021 |
#164 in Database interfaces
48,003 downloads per month
Used in 6 crates
120KB
3K
SLoC
Sqllogictest
Sqllogictest is a testing framework to verify the correctness of an SQL database. See GitHub Homepage for more information.
This crate implements a sqllogictest parser and runner library in Rust.
lib.rs
:
Sqllogictest parser and runner.
This crate supports multiple extensions beyond the original sqllogictest format. See the README for more information.
Usage
For how to use the CLI tool backed by this library, see the README.
For using the crate as a lib, and implement your custom driver, see below.
Implement [DB
] trait for your database structure:
struct MyDatabase {
// fields
}
#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)]
enum MyError {
// variants
}
impl sqllogictest::DB for MyDatabase {
type Error = MyError;
// Or define your own column type
type ColumnType = sqllogictest::DefaultColumnType;
fn run(
&mut self,
sql: &str,
) -> Result<sqllogictest::DBOutput<Self::ColumnType>, Self::Error> {
// TODO
Ok(sqllogictest::DBOutput::StatementComplete(0))
}
}
// Then create a `Runner` on your database instance, and run the tests:
let mut tester = sqllogictest::Runner::new(|| async {
let db = MyDatabase {
// fields
};
Ok(db)
});
let _res = tester.run_file("../tests/slt/basic.slt");
// You can also parse the script and execute the records separately:
let records = sqllogictest::parse_file("../tests/slt/basic.slt").unwrap();
for record in records {
let _res = tester.run(record);
}
Dependencies
~9–19MB
~275K SLoC