init
This commit is contained in:
commit
3299d3cc4c
14 changed files with 3920 additions and 0 deletions
27
src/lib.rs
Normal file
27
src/lib.rs
Normal 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()
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue