This commit is contained in:
JMARyA 2024-12-17 23:28:43 +01:00
commit 3299d3cc4c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
14 changed files with 3920 additions and 0 deletions

27
src/lib.rs Normal file
View file

@ -0,0 +1,27 @@
use tokio::sync::OnceCell;
pub mod result;
pub mod request;
pub mod user;
pub mod page;
// Postgres
pub static PG: OnceCell<sqlx::PgPool> = OnceCell::const_new();
#[macro_export]
macro_rules! get_pg {
() => {
if let Some(client) = $crate::PG.get() {
client
} else {
let client = sqlx::postgres::PgPoolOptions::new()
.max_connections(5)
.connect(&std::env::var("DATABASE_URL").unwrap())
.await
.unwrap();
$crate::PG.set(client).unwrap();
$crate::PG.get().unwrap()
}
};
}