19 lines
556 B
Rust
Executable File
19 lines
556 B
Rust
Executable File
use sqlx::PgPool;
|
|
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
|
|
use tracing::info;
|
|
|
|
pub(crate) type DbPool = PgPool;
|
|
|
|
pub(crate) async fn create_pool() -> Result<DbPool, sqlx::Error> {
|
|
info!("Creating database connection pool...");
|
|
PgPoolOptions::new()
|
|
.max_connections(5)
|
|
.connect_with(PgConnectOptions::new())
|
|
.await
|
|
}
|
|
|
|
pub(crate) async fn run_migrations(pool: &DbPool) -> Result<(), sqlx::migrate::MigrateError> {
|
|
info!("Running database migrations...");
|
|
sqlx::migrate!("./migrations").run(pool).await
|
|
}
|