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:
oxalica 2024-09-21 07:28:41 -04:00
parent b955d32099
commit fafd2de2e3
11 changed files with 769 additions and 669 deletions

View file

@ -20,7 +20,7 @@ use tokio::sync::broadcast;
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
use tokio_stream::wrappers::BroadcastStream;
use crate::database::ConnectionExt;
use crate::database::TransactionOps;
use crate::AppState;
#[derive(Debug, Deserialize)]
@ -145,8 +145,7 @@ pub async fn handle_ws(st: Arc<AppState>, ws: &mut WebSocket) -> Result<Infallib
let (uid, _) = st
.db
.get()
.get_user(&auth.signee.user)
.with_read(|txn| txn.get_user(&auth.signee.user))
.map_err(|err| anyhow!("{}", err.message))?;
// FIXME: Consistency of id's sign.
uid as u64