Create client to establish connection with discord and add basic framework with sample command
This commit is contained in:
49
cipher_database/src/postgres/repository/mod.rs
Normal file
49
cipher_database/src/postgres/repository/mod.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use diesel_async::pooled_connection::bb8::Pool;
|
||||
use diesel_async::pooled_connection::bb8::PooledConnection;
|
||||
use diesel_async::AsyncPgConnection;
|
||||
use cipher_core::repository::Repository;
|
||||
use cipher_core::repository::RepositoryError;
|
||||
use cipher_core::repository::RepositoryProvider;
|
||||
|
||||
use crate::BackendError;
|
||||
|
||||
mod user_repository;
|
||||
|
||||
pub struct PostgresRepository<'a> {
|
||||
conn: PooledConnection<'a, AsyncPgConnection>,
|
||||
}
|
||||
|
||||
impl<'a> PostgresRepository<'a> {
|
||||
pub fn new(conn: PooledConnection<'a, AsyncPgConnection>) -> Self {
|
||||
Self { conn }
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository for PostgresRepository<'_> {
|
||||
type BackendError = BackendError;
|
||||
}
|
||||
|
||||
pub struct PostgresRepositoryProvider {
|
||||
pool: Pool<AsyncPgConnection>,
|
||||
}
|
||||
|
||||
impl PostgresRepositoryProvider {
|
||||
pub fn new(pool: Pool<AsyncPgConnection>) -> Self {
|
||||
Self { pool }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RepositoryProvider for PostgresRepositoryProvider {
|
||||
type BackendError = BackendError;
|
||||
|
||||
type Repository<'a> = PostgresRepository<'a>;
|
||||
|
||||
async fn get(&self) -> Result<Self::Repository<'_>, RepositoryError<Self::BackendError>> {
|
||||
self.pool
|
||||
.get()
|
||||
.await
|
||||
.map(PostgresRepository::new)
|
||||
.map_err(|err| RepositoryError(BackendError::from(err)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user