pub struct Database {
pub base: StarterDatabase,
pub auth: AuthDatabase,
pub logs: LogDatabase,
}
Fields§
§base: StarterDatabase
§auth: AuthDatabase
§logs: LogDatabase
Implementations§
source§impl Database
impl Database
pub async fn new(opts: DatabaseOpts) -> Database
pub async fn init(&self)
sourcepub async fn get_user_by_hashed(
&self,
hashed: String
) -> DefaultReturn<Option<FullUser<String>>>
pub async fn get_user_by_hashed( &self, hashed: String ) -> DefaultReturn<Option<FullUser<String>>>
sourcepub async fn get_user_by_unhashed(
&self,
unhashed: String
) -> DefaultReturn<Option<FullUser<String>>>
pub async fn get_user_by_unhashed( &self, unhashed: String ) -> DefaultReturn<Option<FullUser<String>>>
Get a user by their unhashed ID (hashes ID and then calls Database::get_user_by_hashed()
)
Calls Database::get_user_by_unhashed_st()
if user is invalid.
§Arguments:
unhashed
-String
of the user’s unhashed ID
sourcepub async fn get_user_by_unhashed_st(
&self,
unhashed: String
) -> DefaultReturn<Option<FullUser<String>>>
pub async fn get_user_by_unhashed_st( &self, unhashed: String ) -> DefaultReturn<Option<FullUser<String>>>
Get a user by their unhashed secondary token
§Arguments:
unhashed
-String
of the user’s unhashed secondary token
sourcepub async fn get_user_by_username(
&self,
username: String
) -> DefaultReturn<Option<FullUser<String>>>
pub async fn get_user_by_username( &self, username: String ) -> DefaultReturn<Option<FullUser<String>>>
sourcepub async fn get_level_by_role(
&self,
name: String
) -> DefaultReturn<RoleLevelLog>
pub async fn get_level_by_role( &self, name: String ) -> DefaultReturn<RoleLevelLog>
sourcepub async fn create_user(
&self,
username: String
) -> DefaultReturn<Option<String>>
pub async fn create_user( &self, username: String ) -> DefaultReturn<Option<String>>
Create a new user given their username. Returns their hashed ID
§Arguments:
username
-String
of the user’susername
sourcepub async fn edit_user_metadata_by_name(
&self,
name: String,
metadata: UserMetadata
) -> DefaultReturn<Option<String>>
pub async fn edit_user_metadata_by_name( &self, name: String, metadata: UserMetadata ) -> DefaultReturn<Option<String>>
Update a UserState
’s metadata by its username
sourcepub async fn ban_user_by_name(
&self,
name: String
) -> DefaultReturn<Option<String>>
pub async fn ban_user_by_name( &self, name: String ) -> DefaultReturn<Option<String>>
Ban a UserState
by its username
sourcepub async fn get_follow_by_user(
&self,
user: String,
is_following: String
) -> DefaultReturn<Option<Log>>
pub async fn get_follow_by_user( &self, user: String, is_following: String ) -> DefaultReturn<Option<Log>>
Get a UserFollow
by the username of the user following
§Arguments:
user
- username of user followingis_following
- the username of the user thatuser
is following
sourcepub async fn get_user_followers(
&self,
user: String,
offset: Option<i32>
) -> DefaultReturn<Option<Vec<Log>>>
pub async fn get_user_followers( &self, user: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>
Get the UserFollow
s that are following the given user
§Arguments:
user
- username of user to checkoffset
- optional value representing the SQL fetch offset
sourcepub async fn get_user_following(
&self,
user: String,
offset: Option<i32>
) -> DefaultReturn<Option<Vec<Log>>>
pub async fn get_user_following( &self, user: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>
Get the UserFollow
s that the given user
is following
§Arguments:
user
- username of user to checkoffset
- optional value representing the SQL fetch offset
sourcepub async fn get_user_follow_count(&self, user: String) -> DefaultReturn<usize>
pub async fn get_user_follow_count(&self, user: String) -> DefaultReturn<usize>
sourcepub async fn get_user_following_count(
&self,
user: String
) -> DefaultReturn<usize>
pub async fn get_user_following_count( &self, user: String ) -> DefaultReturn<usize>
sourcepub async fn toggle_user_follow(
&self,
props: &mut UserFollow
) -> DefaultReturn<Option<String>>
pub async fn toggle_user_follow( &self, props: &mut UserFollow ) -> DefaultReturn<Option<String>>
sourcepub async fn get_user_activity(
&self,
username: String,
offset: Option<i32>
) -> DefaultReturn<Option<Vec<(ActivityPost, Vec<ActivityPost>, i32)>>>
pub async fn get_user_activity( &self, username: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<(ActivityPost, Vec<ActivityPost>, i32)>>>
sourcepub async fn get_post_replies(
&self,
id: String,
run_existing_check: bool
) -> DefaultReturn<Option<Vec<ActivityPost>>>
pub async fn get_post_replies( &self, id: String, run_existing_check: bool ) -> DefaultReturn<Option<Vec<ActivityPost>>>
Get all posts replying to another post by the id
of the original post
§Arguments:
id
- post idrun_existing_check
- if we should check that the log exists first
sourcepub async fn get_post_replies_full(
&self,
id: String,
run_existing_check: bool
) -> DefaultReturn<Option<Vec<(ActivityPost, Vec<ActivityPost>, i32)>>>
pub async fn get_post_replies_full( &self, id: String, run_existing_check: bool ) -> DefaultReturn<Option<Vec<(ActivityPost, Vec<ActivityPost>, i32)>>>
Get all posts replying to another post by the id
of the original post
§Arguments:
id
- post idrun_existing_check
- if we should check that the log exists first
sourcepub async fn get_post_by_id(
&self,
id: String
) -> DefaultReturn<Option<ActivityPost>>
pub async fn get_post_by_id( &self, id: String ) -> DefaultReturn<Option<ActivityPost>>
sourcepub async fn create_activity_post(
&self,
props: &mut PCreatePost
) -> DefaultReturn<Option<ActivityPost>>
pub async fn create_activity_post( &self, props: &mut PCreatePost ) -> DefaultReturn<Option<ActivityPost>>
sourcepub async fn delete_activity_post(
&self,
id: String,
as_user: Option<String>
) -> DefaultReturn<bool>
pub async fn delete_activity_post( &self, id: String, as_user: Option<String> ) -> DefaultReturn<bool>
Delete an existing ActivityPost
§Arguments:
id
- post idas_user
- The username of the user creating the post
sourcepub async fn get_post_favorites(&self, id: String) -> DefaultReturn<i32>
pub async fn get_post_favorites(&self, id: String) -> DefaultReturn<i32>
Get the number of PostFavoriteLog
s an ActivityPost
has
sourcepub async fn get_user_post_favorite(
&self,
user: String,
post_id: String,
skip_existing_check: bool
) -> DefaultReturn<Option<Log>>
pub async fn get_user_post_favorite( &self, user: String, post_id: String, skip_existing_check: bool ) -> DefaultReturn<Option<Log>>
Check if a user has favorited a post
sourcepub async fn toggle_user_post_favorite(
&self,
user: String,
post_id: String
) -> DefaultReturn<Option<String>>
pub async fn toggle_user_post_favorite( &self, user: String, post_id: String ) -> DefaultReturn<Option<String>>
Toggle a PostFavoriteLog
on a ActivityPost
by user
and post_id
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
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