db.rs (1583B)
1 /* 2 * This file is part of LibEuFin. 3 * Copyright (C) 2026 Taler Systems S.A. 4 5 * LibEuFin is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation; either version 3, or 8 * (at your option) any later version. 9 10 * LibEuFin is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General 13 * Public License for more details. 14 15 * You should have received a copy of the GNU Affero General Public 16 * License along with LibEuFin; see the file COPYING. If not, see 17 * <http://www.gnu.org/licenses/> 18 */ 19 20 use sqlx::PgPool; 21 use taler_api::config::DbCfg; 22 23 use crate::constants::CONFIG_SOURCE; 24 25 pub async fn pool(cfg: &DbCfg) -> anyhow::Result<PgPool> { 26 let pool = taler_common::db::pool(cfg.cfg.clone(), CONFIG_SOURCE.component_name).await?; 27 Ok(pool) 28 } 29 30 pub async fn dbinit(cfg: &DbCfg, reset: bool) -> anyhow::Result<PgPool> { 31 let pool = taler_common::db::pool(cfg.cfg.clone(), CONFIG_SOURCE.component_name).await?; 32 let mut db = pool.acquire().await?; 33 taler_common::db::dbinit( 34 &mut db, 35 cfg.sql_dir.as_ref(), 36 CONFIG_SOURCE.component_name, 37 reset, 38 ) 39 .await?; 40 Ok(pool) 41 } 42 43 #[cfg(test)] 44 pub mod test { 45 46 use libeufin_ebics::db::test::ebics_routine; 47 use sqlx::PgPool; 48 use taler_macros::db_test; 49 50 #[db_test] 51 pub async fn ebics(db: PgPool) { 52 ebics_routine(&db).await; 53 } 54 }