fix: postgres

This commit is contained in:
trisua 2025-04-03 15:07:57 -04:00
parent dcd5f359c6
commit 27d7c2f4b5
29 changed files with 298 additions and 224 deletions

View file

@ -13,6 +13,7 @@ use bb8_postgres::{
use std::collections::HashMap;
use tetratto_l10n::{LangFile, read_langs};
use tokio_postgres::{Config as PgConfig, NoTls, Row, types::ToSql};
use std::str::FromStr;
pub type Result<T> = std::result::Result<T, tokio_postgres::Error>;
pub type Connection<'a> = PooledConnection<'a, PostgresConnectionManager<NoTls>>;
@ -35,13 +36,14 @@ impl DataManager {
/// Create a new [`DataManager`] (and init database).
pub async fn new(config: Config) -> Result<Self> {
let manager = PostgresConnectionManager::new(
{
let mut c = PgConfig::new();
c.user(&config.database.user);
c.password(&config.database.password);
c.dbname(&config.database.name);
c
},
PgConfig::from_str(&format!(
"postgresql://{}:{}@{}/{}?target_session_attrs=read-write",
config.database.user,
config.database.password,
config.database.url,
config.database.name
))
.unwrap(),
NoTls,
);
@ -144,3 +146,13 @@ macro_rules! execute {
crate::database::execute_helper($conn, $sql, &[]).await
};
}
#[macro_export]
macro_rules! params {
() => {
&[]
};
($($x:expr),+ $(,)?) => {
&[$(&$x),+]
};
}