backbone_bucket/infrastructure/persistence/
thumbnail_repository.rs1use anyhow::Result;
9use sqlx::PgPool;
10
11use crate::domain::entity::Thumbnail;
12
13pub const TABLE_NAME: &str = "bucket.thumbnails";
15
16pub struct ThumbnailRepository(
21 backbone_orm::GenericCrudRepository<Thumbnail, backbone_orm::SoftDelete>,
22);
23
24impl std::ops::Deref for ThumbnailRepository {
25 type Target = backbone_orm::GenericCrudRepository<Thumbnail, backbone_orm::SoftDelete>;
26 fn deref(&self) -> &Self::Target { &self.0 }
27}
28
29impl ThumbnailRepository {
30 pub fn new(pool: PgPool) -> Self {
32 Self(backbone_orm::GenericCrudRepository::new(pool, TABLE_NAME))
33 }
34}
35
36impl ThumbnailRepository {
37 pub async fn find_by_storage_key(&self, storage_key: &str) -> Result<Option<Thumbnail>> {
39 self.find_by_text_field("storage_key", storage_key).await
40 }
41
42 pub async fn exists_by_storage_key(&self, storage_key: &str) -> Result<bool> {
44 self.exists_by_text_field("storage_key", storage_key).await
45 }
46
47}
48
49backbone_core::impl_crud_repository!(ThumbnailRepository, Thumbnail, soft_delete);