sqlx-utils 1.1.3

Utilities for working with SQLx in a structured and efficient way, both when developing and running
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::types::Pool;
use std::sync::OnceLock;

pub static DB_POOL: OnceLock<Pool> = OnceLock::new();

#[inline(always)]
#[tracing::instrument(skip(pool), level = "trace")]
pub fn initialize_db_pool(pool: Pool) {
    DB_POOL.set(pool).expect("Failed to set DB_POOL")
}

#[inline(always)]
#[tracing::instrument(level = "trace")]
pub fn get_db_pool() -> &'static Pool {
    DB_POOL.get().expect("DB_POOL is not initialized, please call `initialize_db_pool` before using it, preferably as early as possible in your program!")
}