From a0c99d05ebd4e55c94ecf272eec171df799f6226 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Thu, 24 Mar 2022 13:16:41 -0500 Subject: [PATCH] Create initial trait representation for database --- src/main.rs | 1 + src/repo.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/repo.rs diff --git a/src/main.rs b/src/main.rs index 4b2a059..6ed8cc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,7 @@ mod migrate; mod process; mod processor; mod range; +mod repo; mod serde_str; mod store; mod tmp_file; diff --git a/src/repo.rs b/src/repo.rs new file mode 100644 index 0000000..8da18f6 --- /dev/null +++ b/src/repo.rs @@ -0,0 +1,74 @@ +use crate::{store::Identifier, upload_manager::Details}; +use futures_util::Stream; +use uuid::Uuid; + +pub(crate) struct Alias { + id: Uuid, + extension: String, +} +pub(crate) struct DeleteToken { + id: Uuid, +} +pub(crate) struct AlreadyExists; + +#[async_trait::async_trait] +pub(crate) trait SettingsRepo { + type Error: std::error::Error; + + async fn set(&self, key: &'static [u8], value: Vec) -> Result<(), Self::Error>; + async fn get(&self, key: &'static [u8]) -> Result>, Self::Error>; + async fn remove(&self, key: &'static [u8]) -> Result<(), Self::Error>; +} + +#[async_trait::async_trait] +pub(crate) trait IdentifierRepo { + type Hash: AsRef<[u8]>; + type Error: std::error::Error; + + async fn relate_details(&self, identifier: I, details: Details) -> Result<(), Self::Error>; + async fn details(&self, identifier: I) -> Result, Self::Error>; + + async fn relate_hash(&self, identifier: I, hash: Self::Hash) -> Result<(), Self::Error>; + async fn hash(&self, identifier: I) -> Result; + + async fn cleanup(&self, identifier: I) -> Result<(), Self::Error>; +} + +#[async_trait::async_trait] +pub(crate) trait HashRepo { + type Hash: AsRef<[u8]>; + type Error: std::error::Error; + type Stream: Stream>; + + async fn hashes(&self) -> Self::Stream; + + async fn create(&self, hash: Self::Hash) -> Result, Self::Error>; + + async fn relate_alias(&self, hash: Self::Hash, alias: Alias) -> Result<(), Self::Error>; + async fn remove_alias(&self, hash: Self::Hash, alias: Alias) -> Result<(), Self::Error>; + async fn aliases(&self, hash: Self::Hash) -> Result, Self::Error>; + + async fn cleanup(&self, hash: Self::Hash) -> Result<(), Self::Error>; +} + +#[async_trait::async_trait] +pub(crate) trait AliasRepo { + type Hash: AsRef<[u8]>; + type Error: std::error::Error; + + async fn create(&self, alias: Alias) -> Result, Self::Error>; + + async fn create_delete_token( + &self, + alias: Alias, + ) -> Result, Self::Error>; + async fn delete_token(&self, alias: Alias) -> Result; + + async fn relate_hash(&self, alias: Alias, hash: Self::Hash) -> Result<(), Self::Error>; + async fn hash(&self, alias: Alias) -> Result; + + async fn relate_identifier(&self, alias: Alias, identifier: I) -> Result<(), Self::Error>; + async fn identifier(&self, alias: Alias) -> Result; + + async fn cleanup(&self, alias: Alias) -> Result<(), Self::Error>; +}