mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-14 01:35:35 +00:00
refactor(database)!: decouple SQLs from backend logic and cache stmts
This decouples SQLs from handler logic, makes it easier for auditing and caching. It also enables the possibility to switch or support multiple database backends.
This commit is contained in:
parent
b955d32099
commit
fafd2de2e3
11 changed files with 769 additions and 669 deletions
31
blahd/src/database/tests.rs
Normal file
31
blahd/src/database/tests.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#![expect(clippy::print_stdout, reason = "allowed in tests for debugging")]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn init_sql_valid() {
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(INIT_SQL).unwrap();
|
||||
|
||||
// Instantiate view to check syntax and availability of `unixepoch()`.
|
||||
// It requires sqlite >= 3.38.0 (2022-02-22) which is not available by default on GitHub CI.
|
||||
let ret = conn
|
||||
.query_row(
|
||||
"SELECT COUNT(*) FROM `valid_user_act_key`",
|
||||
params![],
|
||||
|row| row.get::<_, i64>(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(ret, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stmt_cache_capacity() {
|
||||
let src = std::fs::read_to_string("src/database.rs").unwrap();
|
||||
let sql_cnt = src.matches("prepare_cached_and_bind!").count();
|
||||
println!("found {sql_cnt} SQLs");
|
||||
assert_ne!(sql_cnt, 0);
|
||||
assert!(
|
||||
sql_cnt <= STMT_CACHE_CAPACITY,
|
||||
"stmt cache capacity {STMT_CACHE_CAPACITY} is too small, found {sql_cnt} SQLs",
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue