Struct guppy::db::Database

source ·
pub struct Database {
    pub base: StarterDatabase,
    pub auth: AuthDatabase,
    pub logs: LogDatabase,
}

Fields§

§base: StarterDatabase§auth: AuthDatabase§logs: LogDatabase

Implementations§

source§

impl Database

source

pub async fn new(opts: DatabaseOpts) -> Database

source

pub async fn init(&self)

source

pub async fn get_user_by_hashed( &self, hashed: String ) -> DefaultReturn<Option<FullUser<String>>>

Get a user by their hashed ID

Arguments:
  • hashed - String of the user’s hashed ID
source

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
source

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
source

pub async fn get_user_by_username( &self, username: String ) -> DefaultReturn<Option<FullUser<String>>>

Get a user by their username

Arguments:
  • username - String of the user’s username
source

pub async fn get_level_by_role( &self, name: String ) -> DefaultReturn<RoleLevelLog>

Get a RoleLevel by its name

Arguments:
  • name - String of the level’s role name
source

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’s username
source

pub async fn edit_user_metadata_by_name( &self, name: String, metadata: UserMetadata ) -> DefaultReturn<Option<String>>

Update a UserState’s metadata by its username

source

pub async fn ban_user_by_name( &self, name: String ) -> DefaultReturn<Option<String>>

Ban a UserState by its username

source

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 following
  • is_following - the username of the user that user is following
source

pub async fn get_user_followers( &self, user: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get the UserFollows that are following the given user

Arguments:
  • user - username of user to check
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_user_following( &self, user: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get the UserFollows that the given user is following

Arguments:
  • user - username of user to check
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_user_follow_count(&self, user: String) -> DefaultReturn<usize>

Get the amount of followers a user has

Arguments:
  • user - username of user to check
source

pub async fn get_user_following_count( &self, user: String ) -> DefaultReturn<usize>

Get the amount of users a user is following

Arguments:
  • user - username of user to check
source

pub async fn toggle_user_follow( &self, props: &mut UserFollow ) -> DefaultReturn<Option<String>>

Toggle the following status of user on is_following (UserFollow)

Arguments:
source

pub async fn get_user_activity( &self, username: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<(ActivityPost, Vec<ActivityPost>, i32)>>>

Get all user activity posts by username

Arguments:
  • username - String
  • offset - optional value representing the SQL fetch offset
source

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 id
  • run_existing_check - if we should check that the log exists first
source

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 id
  • run_existing_check - if we should check that the log exists first
source

pub async fn get_post_by_id( &self, id: String ) -> DefaultReturn<Option<ActivityPost>>

Get an ActivityPost by its id

Arguments:
  • id - String of the post’s id
source

pub async fn create_activity_post( &self, props: &mut PCreatePost ) -> DefaultReturn<Option<ActivityPost>>

Create a new ActivityPost

Arguments:
source

pub async fn delete_activity_post( &self, id: String, as_user: Option<String> ) -> DefaultReturn<bool>

Delete an existing ActivityPost

Arguments:
  • id - post id
  • as_user - The username of the user creating the post
source

pub async fn get_post_favorites(&self, id: String) -> DefaultReturn<i32>

Get the number of PostFavoriteLogs an ActivityPost has

source

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

source

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§

source§

impl Clone for Database

source§

fn clone(&self) -> Database

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more