Create client to establish connection with discord and add basic framework with sample command

This commit is contained in:
2025-01-29 22:22:08 +00:00
parent fc07051558
commit a719b143de
50 changed files with 1712 additions and 128 deletions

View File

@@ -0,0 +1,50 @@
use diesel::SqliteConnection;
use diesel_async::pooled_connection::bb8::Pool;
use diesel_async::pooled_connection::bb8::PooledConnection;
use diesel_async::sync_connection_wrapper::SyncConnectionWrapper;
use cipher_core::repository::Repository;
use cipher_core::repository::RepositoryError;
use cipher_core::repository::RepositoryProvider;
use crate::BackendError;
mod user_repository;
pub struct SqliteRepository<'a> {
conn: PooledConnection<'a, SyncConnectionWrapper<SqliteConnection>>,
}
impl<'a> SqliteRepository<'a> {
pub fn new(conn: PooledConnection<'a, SyncConnectionWrapper<SqliteConnection>>) -> Self {
Self { conn }
}
}
impl Repository for SqliteRepository<'_> {
type BackendError = BackendError;
}
pub struct SqliteRepositoryProvider {
pool: Pool<SyncConnectionWrapper<SqliteConnection>>,
}
impl SqliteRepositoryProvider {
pub fn new(pool: Pool<SyncConnectionWrapper<SqliteConnection>>) -> Self {
Self { pool }
}
}
#[async_trait::async_trait]
impl RepositoryProvider for SqliteRepositoryProvider {
type BackendError = BackendError;
type Repository<'a> = SqliteRepository<'a>;
async fn get(&self) -> Result<Self::Repository<'_>, RepositoryError<Self::BackendError>> {
self.pool
.get()
.await
.map(SqliteRepository::new)
.map_err(|err| RepositoryError(BackendError::from(err)))
}
}