/ src / db / mod.rs
mod.rs
 1  use sqlx::{Pool, Postgres, Transaction};
 2  
 3  use crate::registry_error::{RegistryError, RegistryResult};
 4  
 5  pub mod blob_repository;
 6  pub mod manifest_layer_repository;
 7  pub mod manifest_repository;
 8  pub mod repository_repository;
 9  pub mod upload_session_repository;
10  
11  pub type DB = Postgres;
12  
13  pub async fn new_transaction(db_pool: &Pool<DB>) -> RegistryResult<Transaction<'_, DB>> {
14      match db_pool.begin().await {
15          Ok(transaction) => Ok(transaction),
16          Err(err) => {
17              error!("Failed to create transaction: {:?}", err);
18              Err(RegistryError::SqlxError(err))
19          }
20      }
21  }