feat: Type-erase Database backend for simpler code

This commit is contained in:
selfhoster selfhoster 2026-09-19 14:39:01 +02:00
commit ccbd97b836
17 changed files with 108 additions and 117 deletions

View file

@ -45,7 +45,7 @@ pub struct FilesystemDatabase {
}
impl FilesystemDatabase {
pub async fn from_path(path: impl AsRef<Utf8Path>) -> Result<Database<Self>, BoxedError> {
pub async fn from_path(path: impl AsRef<Utf8Path>) -> Result<Database, BoxedError> {
let path = path.as_ref();
let s = tokio::fs::read(path)
.await
@ -67,6 +67,7 @@ impl FilesystemDatabase {
}
}
#[async_trait::async_trait]
impl DatabaseInterface for FilesystemDatabase {
async fn create_domain(
&mut self,
@ -84,15 +85,12 @@ impl DatabaseInterface for FilesystemDatabase {
Ok(Ok(()))
}
fn get_domain(&self, domain: &str) -> impl Future<Output = Result<Option<Domain>, BoxedError>> {
self.inner.get_domain(domain)
async fn get_domain(&self, domain: &str) -> Result<Option<Domain>, BoxedError> {
self.inner.get_domain(domain).await
}
fn get_user(
&self,
req_user: &UserRef,
) -> impl Future<Output = Result<Option<User>, BoxedError>> {
self.inner.get_user(req_user)
async fn get_user(&self, req_user: &UserRef) -> Result<Option<User>, BoxedError> {
self.inner.get_user(req_user).await
}
async fn create_user(
@ -128,18 +126,15 @@ impl DatabaseInterface for FilesystemDatabase {
Ok(Ok(()))
}
fn list_all_domains(&self) -> impl Future<Output = Result<Vec<Domain>, BoxedError>> {
self.inner.list_all_domains()
async fn list_all_domains(&self) -> Result<Vec<Domain>, BoxedError> {
self.inner.list_all_domains().await
}
fn list_all_users(&self) -> impl Future<Output = Result<Vec<User>, BoxedError>> {
self.inner.list_all_users()
async fn list_all_users(&self) -> Result<Vec<User>, BoxedError> {
self.inner.list_all_users().await
}
fn list_domain_users(
&self,
domain: Option<String>,
) -> impl Future<Output = Result<Vec<User>, BoxedError>> {
self.inner.list_domain_users(domain)
async fn list_domain_users(&self, domain: Option<String>) -> Result<Vec<User>, BoxedError> {
self.inner.list_domain_users(domain).await
}
}