From 05bd6576a9f198ee8fe01a1d3e486a285177a6f1 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Fri, 16 Dec 2022 18:16:59 +0100 Subject: [PATCH] Define DB types --- src/db.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/db.rs b/src/db.rs index fb665ca..97f60a7 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,9 @@ use anyhow::{Context, Result}; use chrono::offset::Local; -use diesel::prelude::*; -use diesel::r2d2::{ConnectionManager, Pool, PooledConnection}; +use diesel::{ + prelude::*, + r2d2::{ConnectionManager, Pool, PooledConnection}, +}; use std::env; use tracing::error; @@ -9,21 +11,23 @@ use crate::config::Hook; use crate::models::{HookLog, NewHookLog}; use crate::schema::hooklog; -pub type DBPool = Pool>; +type DBConnectionManager = ConnectionManager; +pub type DBPool = Pool; +type DBConnection = PooledConnection; pub fn establish_connection_pool() -> Result { let database_url_var = "DATABASE_URL"; let database_url = env::var(database_url_var) .with_context(|| format!("Environment variable {database_url_var} missing!"))?; - let manager = ConnectionManager::::new(database_url); + let manager = DBConnectionManager::new(database_url); Pool::builder() .build(manager) .context("Could not build database connection pool!") } -fn get_conn(pool: &DBPool) -> Result>> { +fn get_conn(pool: &DBPool) -> Result { pool.get().context("Could not get database pool!") }