pub struct Asset { /* private fields */ }Expand description
A record in the assets table representing one user’s ownership of a blob.
The server stores files by their BLAKE3 hash (CAS semantics). Multiple users
can upload identical files — each gets their own Asset row pointing to the
same hash. When a user deletes their asset, only their row is removed. The
physical blob is only deleted when no Asset rows reference its hash anymore.
This mirrors Unix hard-link semantics.
Implementations§
Source§impl Asset
impl Asset
Sourcepub async fn exists(pool: &SqlitePool, hash: Vec<u8>) -> Result<bool>
pub async fn exists(pool: &SqlitePool, hash: Vec<u8>) -> Result<bool>
Returns whether asset exists with given hash
§Errors
- Fails with [
sqlx::Error] if fails to work with database
Sourcepub async fn create(
pool: &SqlitePool,
user: i64,
tag: AssetTag,
metadata: &Metadata,
) -> Result<()>
pub async fn create( pool: &SqlitePool, user: i64, tag: AssetTag, metadata: &Metadata, ) -> Result<()>
Registers an asset entry to the assets entity
§Errors
- Returns [
sqlx::Error::Database] for uniqueness violation, because ofuuidbeing PRIMARY KEY, which happens very (very) rarely. - Otherwise, this can fail on querrying databases
Sourcepub async fn delete(pool: &SqlitePool, user: i64, hash: &[u8]) -> Result<()>
pub async fn delete(pool: &SqlitePool, user: i64, hash: &[u8]) -> Result<()>
Deletes user’s ownership over an asset
- Returns
Ok(true), if no other user owns same asset. Good signal to wipe that asset physically off the server. - Return
Ok(false), if user doesn’t own the file, or other users have own the same file.
§Errors
Returns [sqlx::Error] if a database transaction fails.
Sourcepub async fn owned_by(pool: &SqlitePool, user: i64, hash: &[u8]) -> Result<bool>
pub async fn owned_by(pool: &SqlitePool, user: i64, hash: &[u8]) -> Result<bool>
Checks if any Asset with provided hash exists, and is owned by the specified user as well
It’s different from Asset::exists, because it checks for ownership.
Required for situations where user tries to access an asset, this returns the proof of it.
§Errors
Returns [sqlx::Error] if the database query fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Asset
impl RefUnwindSafe for Asset
impl Send for Asset
impl Sync for Asset
impl Unpin for Asset
impl UnsafeUnpin for Asset
impl UnwindSafe for Asset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more