This commit is contained in:
18
src/db.rs
Executable file
18
src/db.rs
Executable file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user