authbeam::database

Struct Database

source
pub struct Database {
    pub base: StarterDatabase,
    pub config: ServerOptions,
    pub http: Client,
    pub citrus: CitrusClient,
}
Expand description

Database connector

Fields§

§base: StarterDatabase§config: ServerOptions§http: Client§citrus: CitrusClient

Implementations§

source§

impl Database

source

pub async fn new( database_options: DatabaseOpts, server_options: ServerOptions, ) -> Self

Create a new Database

source

pub fn env_options() -> DatabaseOpts

Pull databeam::DatabaseOpts from env

source

pub async fn init(&self)

Init database

source

pub fn collect_split_without_stupid_reference( input: Split<'_, &str>, ) -> Vec<String>

Collect from Split<&str> while cloning everything

source

pub async fn audit(&self, actor_id: String, content: String) -> Result<()>

Create a moderator audit log entry

source

pub async fn get_profile(&self, id: String) -> Result<Box<Profile>>

Fetch a profile correctly

source

pub async fn get_profile_by_hashed( &self, hashed: String, ) -> Result<Box<Profile>>

Get a Profile by their hashed ID

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

pub async fn get_profile_by_unhashed( &self, unhashed: String, ) -> Result<Box<Profile>>

Get a user by their unhashed ID (hashes ID and then calls Database::get_profile_by_hashed())

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

pub async fn get_profile_by_ip(&self, ip: String) -> Result<Box<Profile>>

Get a Profile by their IP

§Arguments:
  • hashed - String of the profile’s IP
source

pub async fn get_profile_by_username_password( &self, username: String, password: String, ) -> Result<Profile>

Get a user by their unhashed secondary token

§Arguments:
  • unhashed - String of the user’s unhashed secondary token
source

pub async fn get_profile_by_username( &self, username: String, ) -> Result<Box<Profile>>

Get a user by their username

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

pub async fn get_profile_by_id(&self, id: String) -> Result<Box<Profile>>

Get a user by their id

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

pub fn validate_username(username: String) -> Result<()>

Validate a username

source

pub async fn create_profile( &self, props: ProfileCreate, user_ip: String, ) -> Result<String>

Create a new user given their username. Returns their unhashed token

§Arguments:
  • username - String of the user’s username
  • user_ip - the ip address of the user registering
source

pub fn allowed_custom_keys(&self) -> Vec<&'static str>

source

pub async fn update_profile_metadata( &self, id: String, metadata: ProfileMetadata, ) -> Result<()>

Update a Profile’s metadata by its id

source

pub async fn update_profile_tokens( &self, id: String, tokens: Vec<String>, ips: Vec<String>, token_context: Vec<TokenContext>, ) -> Result<()>

Update a Profile’s tokens (and IPs/token_contexts) by its id

source

pub async fn update_profile_badges( &self, id: String, badges: Vec<(String, String, String)>, ) -> Result<()>

Update a Profile’s badges by its id

source

pub async fn update_profile_labels( &self, id: String, labels: Vec<String>, ) -> Result<()>

Update a Profile’s labels by its id

source

pub async fn update_profile_tier(&self, id: String, tier: i32) -> Result<()>

Update a Profile’s tier by its ID

source

pub async fn update_profile_group(&self, id: String, group: i32) -> Result<()>

Update a Profile’s gid by its id

source

pub async fn update_profile_password( &self, id: String, password: String, new_password: String, do_password_check: bool, ) -> Result<()>

Update a Profile’s password by its name and password

source

pub async fn update_profile_username( &self, id: String, password: String, new_name: String, ) -> Result<()>

Update a Profile’s username by its id and password

source

async fn delete_profile(&self, id: String) -> Result<()>

Delete a profile

VALIDATION SHOULD BE DONE BEFORE THIS!!

source

pub async fn delete_profile_by_id(&self, id: String) -> Result<()>

Delete an existing Profile by its id

source

pub async fn get_group_by_id(&self, id: i32) -> Result<Group>

Get a group by its id

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

pub async fn get_follow( &self, user: String, following: String, ) -> Result<UserFollow>

Get an existing UserFollow

§Arguments:
  • user
  • following
source

pub async fn get_followers( &self, user: String, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

Get all existing UserFollows where following is the value of user

§Arguments:
  • user
source

pub async fn get_followers_paginated( &self, user: String, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

Get all existing UserFollows where following is the value of user, 50 at a time

§Arguments:
  • user
  • page
source

pub async fn get_followers_count(&self, user: String) -> usize

Get the number of followers user has

§Arguments:
  • user
source

pub async fn get_following( &self, user: String, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

Get all existing UserFollows where user is the value of user

§Arguments:
  • user
source

pub async fn get_following_paginated( &self, user: String, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

Get all existing UserFollows where user is the value of user, 50 at a time

§Arguments:
  • user
  • page
source

pub async fn get_following_count(&self, user: String) -> usize

Get the number of users user is following

§Arguments:
  • user
source

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

Toggle the following status of user on following (UserFollow)

§Arguments:
source

pub async fn force_remove_user_follow( &self, props: &mut UserFollow, ) -> Result<()>

Force remove the following status of user on following (UserFollow)

§Arguments:
source

pub async fn get_notification(&self, id: String) -> Result<Notification>

Get an existing notification

§Arguments:
  • id
source

pub async fn get_notifications_by_recipient( &self, recipient: String, ) -> Result<Vec<Notification>>

Get all notifications by their recipient

§Arguments:
  • recipient
source

pub async fn get_notification_count_by_recipient( &self, recipient: String, ) -> usize

Get the number of notifications by their recipient

§Arguments:
  • recipient
source

pub async fn get_notifications_by_recipient_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<Notification>>

Get all notifications by their recipient, 50 at a time

§Arguments:
  • recipient
  • page
source

pub async fn create_notification( &self, props: NotificationCreate, id: Option<String>, ) -> Result<()>

Create a new notification

§Arguments:
source

pub async fn delete_notification( &self, id: String, user: Box<Profile>, ) -> Result<()>

Delete an existing notification

Notifications can only be deleted by their recipient.

§Arguments:
  • id - the ID of the notification
  • user - the user doing this
source

pub async fn delete_notifications_by_recipient( &self, recipient: String, user: Box<Profile>, ) -> Result<()>

Delete all existing notifications by their recipient

§Arguments:
  • id - the ID of the notification
  • user - the user doing this
source

pub async fn get_warning(&self, id: String) -> Result<Warning>

Get an existing warning

§Arguments:
  • id
source

pub async fn get_warnings_by_recipient( &self, recipient: String, user: Box<Profile>, ) -> Result<Vec<Warning>>

Get all warnings by their recipient

§Arguments:
  • recipient
  • user - the user doing this
source

pub async fn create_warning( &self, props: WarningCreate, user: Box<Profile>, ) -> Result<()>

Create a new warning

§Arguments:
source

pub async fn delete_warning(&self, id: String, user: Box<Profile>) -> Result<()>

Delete an existing warning

Warnings can only be deleted by their moderator or admins.

§Arguments:
  • id - the ID of the warning
  • user - the user doing this
source

pub async fn get_ipban(&self, id: String) -> Result<IpBan>

Get an existing IpBan

§Arguments:
  • id
source

pub async fn get_ipban_by_ip(&self, ip: String) -> Result<IpBan>

Get an existing IpBan by its IP

§Arguments:
  • ip
source

pub async fn get_ipbans(&self, user: Box<Profile>) -> Result<Vec<IpBan>>

Get all IpBans

§Arguments:
  • user - the user doing this
source

pub async fn create_ipban( &self, props: IpBanCreate, user: Box<Profile>, ) -> Result<()>

Create a new IpBan

§Arguments:
  • props - IpBanCreate
  • user - the user creating this ban
source

pub async fn delete_ipban(&self, id: String, user: Box<Profile>) -> Result<()>

Delete an existing IpBan

§Arguments:
  • id - the ID of the ban
  • user - the user doing this
source

pub async fn get_user_relationship( &self, user: String, other: String, ) -> (RelationshipStatus, String, String)

Get the membership status of the given user and the other user

§Arguments
  • user - the ID of the first user
  • other - the ID of the second user
source

pub async fn set_user_relationship_status( &self, one: String, two: String, status: RelationshipStatus, disable_notifications: bool, ) -> Result<()>

Set the relationship of user one and two

§Arguments
  • one - the ID of the first user
  • two - the ID of the second user
  • status - the new relationship status, setting to “Unknown” will remove the relationship
  • disable_notifications
source

pub async fn get_user_relationships( &self, user: String, ) -> Result<Vec<(Box<Profile>, RelationshipStatus)>>

Get all relationships owned by user (ownership is the relationship’s one field)

§Arguments
  • user
source

pub async fn get_user_relationships_of_status( &self, user: String, status: RelationshipStatus, ) -> Result<Vec<(Box<Profile>, RelationshipStatus)>>

Get all relationships owned by user (ownership is the relationship’s one field)

§Arguments
  • user
  • status
source

pub async fn get_user_participating_relationships_of_status( &self, user: String, status: RelationshipStatus, ) -> Result<Vec<(Box<Profile>, Box<Profile>)>>

Get all relationships where user is either one or two and the status is status

§Arguments
  • user
  • status
source

pub async fn get_user_participating_relationships_of_status_paginated( &self, user: String, status: RelationshipStatus, page: i32, ) -> Result<Vec<(Box<Profile>, Box<Profile>)>>

Get all relationships where user is either one or two and the status is status, 50 at a time

§Arguments
  • user
  • status
  • page
source

pub async fn get_friendship_count_by_user(&self, id: String) -> usize

Get the number of friends a user has

§Arguments
  • id
source

pub async fn get_ipblock(&self, id: String) -> Result<IpBlock>

Get an existing IpBlock

§Arguments:
  • id
source

pub async fn get_ipblock_by_ip( &self, ip: String, user: String, ) -> Result<IpBlock>

Get an existing IpBlock by its IP and its user

§Arguments:
  • ip
  • user
source

pub async fn get_ipblocks(&self, query_user: String) -> Result<Vec<IpBlock>>

Get all [IpBlocks]s for the given query_user

§Arguments:
  • query_user - the ID of the user the blocks belong to
source

pub async fn create_ipblock( &self, props: IpBlockCreate, user: Box<Profile>, ) -> Result<()>

Create a new IpBlock

§Arguments:
source

pub async fn delete_ipblock(&self, id: String, user: Box<Profile>) -> Result<()>

Delete an existing IpBlock

§Arguments:
  • id - the ID of the block
  • user - the user doing this
source

pub async fn get_mail(&self, id: String) -> Result<Mail>

Get an existing mail

§Arguments:
  • id
source

pub async fn get_mail_by_recipient_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<(Mail, Box<Profile>)>>

Get all mail by their recipient, 50 at a time

§Arguments:
  • recipient
  • page
source

pub async fn get_mail_by_recipient_sent_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<(Mail, Box<Profile>)>>

Get all mail by their recipient, 50 at a time

§Arguments:
  • recipient
  • page
source

pub async fn create_mail( &self, props: MailCreate, author: String, ) -> Result<Mail>

Create a new mail

§Arguments:
source

pub async fn delete_mail(&self, id: String, user: Box<Profile>) -> Result<()>

Delete an existing mail

Mail can only be deleted by their recipient.

§Arguments:
  • id - the ID of the mail
  • user - the user doing this
source

pub async fn update_mail_state( &self, id: String, state: MailState, user: Box<Profile>, ) -> Result<()>

Update mail state

§Arguments:
source

pub async fn gimme_label( &self, res: HashMap<String, String>, ) -> Result<UserLabel>

Get a UserLabel from a database result

source

pub async fn get_label(&self, id: String) -> Result<UserLabel>

Get an existing label

§Arguments:
  • id
source

pub async fn create_label( &self, name: String, author: String, ) -> Result<UserLabel>

Create a new user label

§Arguments
  • name - the name of the label
  • author - the ID of the user creating the label

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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

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 T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

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 T
where U: Into<T>,

source§

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 T
where U: TryFrom<T>,

source§

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 T
where 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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T