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
impl Database
sourcepub async fn new(
database_options: DatabaseOpts,
server_options: ServerOptions,
) -> Self
pub async fn new( database_options: DatabaseOpts, server_options: ServerOptions, ) -> Self
Create a new Database
sourcepub fn env_options() -> DatabaseOpts
pub fn env_options() -> DatabaseOpts
Pull databeam::DatabaseOpts
from env
sourcepub fn collect_split_without_stupid_reference(
input: Split<'_, &str>,
) -> Vec<String>
pub fn collect_split_without_stupid_reference( input: Split<'_, &str>, ) -> Vec<String>
Collect from Split<&str>
while cloning everything
sourcepub async fn audit(&self, actor_id: String, content: String) -> Result<()>
pub async fn audit(&self, actor_id: String, content: String) -> Result<()>
Create a moderator audit log entry
sourcepub async fn get_profile_by_unhashed(
&self,
unhashed: String,
) -> Result<Box<Profile>>
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
sourcepub async fn get_profile_by_username_password(
&self,
username: String,
password: String,
) -> Result<Profile>
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
sourcepub fn validate_username(username: String) -> Result<()>
pub fn validate_username(username: String) -> Result<()>
Validate a username
sourcepub async fn create_profile(
&self,
props: ProfileCreate,
user_ip: String,
) -> Result<String>
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’susername
user_ip
- the ip address of the user registering
pub fn allowed_custom_keys(&self) -> Vec<&'static str>
sourcepub async fn update_profile_metadata(
&self,
id: String,
metadata: ProfileMetadata,
) -> Result<()>
pub async fn update_profile_metadata( &self, id: String, metadata: ProfileMetadata, ) -> Result<()>
Update a Profile
’s metadata by its id
sourcepub async fn update_profile_tokens(
&self,
id: String,
tokens: Vec<String>,
ips: Vec<String>,
token_context: Vec<TokenContext>,
) -> Result<()>
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
sourcepub async fn update_profile_badges(
&self,
id: String,
badges: Vec<(String, String, String)>,
) -> Result<()>
pub async fn update_profile_badges( &self, id: String, badges: Vec<(String, String, String)>, ) -> Result<()>
Update a Profile
’s badges by its id
sourcepub async fn update_profile_labels(
&self,
id: String,
labels: Vec<String>,
) -> Result<()>
pub async fn update_profile_labels( &self, id: String, labels: Vec<String>, ) -> Result<()>
Update a Profile
’s labels by its id
sourcepub async fn update_profile_tier(&self, id: String, tier: i32) -> Result<()>
pub async fn update_profile_tier(&self, id: String, tier: i32) -> Result<()>
Update a Profile
’s tier by its ID
sourcepub async fn update_profile_group(&self, id: String, group: i32) -> Result<()>
pub async fn update_profile_group(&self, id: String, group: i32) -> Result<()>
Update a Profile
’s gid
by its id
sourcepub async fn update_profile_password(
&self,
id: String,
password: String,
new_password: String,
do_password_check: bool,
) -> Result<()>
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
sourcepub async fn update_profile_username(
&self,
id: String,
password: String,
new_name: String,
) -> Result<()>
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
sourceasync fn delete_profile(&self, id: String) -> Result<()>
async fn delete_profile(&self, id: String) -> Result<()>
Delete a profile
VALIDATION SHOULD BE DONE BEFORE THIS!!
sourcepub async fn delete_profile_by_id(&self, id: String) -> Result<()>
pub async fn delete_profile_by_id(&self, id: String) -> Result<()>
Delete an existing Profile
by its id
sourcepub async fn get_group_by_id(&self, id: i32) -> Result<Group>
pub async fn get_group_by_id(&self, id: i32) -> Result<Group>
sourcepub async fn get_follow(
&self,
user: String,
following: String,
) -> Result<UserFollow>
pub async fn get_follow( &self, user: String, following: String, ) -> Result<UserFollow>
sourcepub async fn get_followers(
&self,
user: String,
) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
pub async fn get_followers( &self, user: String, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
sourcepub async fn get_followers_paginated(
&self,
user: String,
page: i32,
) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
pub async fn get_followers_paginated( &self, user: String, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
Get all existing UserFollow
s where following
is the value of user
, 50 at a time
§Arguments:
user
page
sourcepub async fn get_followers_count(&self, user: String) -> usize
pub async fn get_followers_count(&self, user: String) -> usize
sourcepub async fn get_following(
&self,
user: String,
) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
pub async fn get_following( &self, user: String, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
sourcepub async fn get_following_paginated(
&self,
user: String,
page: i32,
) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
pub async fn get_following_paginated( &self, user: String, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>
sourcepub async fn get_following_count(&self, user: String) -> usize
pub async fn get_following_count(&self, user: String) -> usize
sourcepub async fn toggle_user_follow(&self, props: &mut UserFollow) -> Result<()>
pub async fn toggle_user_follow(&self, props: &mut UserFollow) -> Result<()>
sourcepub async fn force_remove_user_follow(
&self,
props: &mut UserFollow,
) -> Result<()>
pub async fn force_remove_user_follow( &self, props: &mut UserFollow, ) -> Result<()>
sourcepub async fn get_notification(&self, id: String) -> Result<Notification>
pub async fn get_notification(&self, id: String) -> Result<Notification>
sourcepub async fn get_notifications_by_recipient(
&self,
recipient: String,
) -> Result<Vec<Notification>>
pub async fn get_notifications_by_recipient( &self, recipient: String, ) -> Result<Vec<Notification>>
sourcepub async fn get_notification_count_by_recipient(
&self,
recipient: String,
) -> usize
pub async fn get_notification_count_by_recipient( &self, recipient: String, ) -> usize
sourcepub async fn get_notifications_by_recipient_paginated(
&self,
recipient: String,
page: i32,
) -> Result<Vec<Notification>>
pub async fn get_notifications_by_recipient_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<Notification>>
sourcepub async fn create_notification(
&self,
props: NotificationCreate,
id: Option<String>,
) -> Result<()>
pub async fn create_notification( &self, props: NotificationCreate, id: Option<String>, ) -> Result<()>
sourcepub async fn delete_notification(
&self,
id: String,
user: Box<Profile>,
) -> Result<()>
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 notificationuser
- the user doing this
sourcepub async fn delete_notifications_by_recipient(
&self,
recipient: String,
user: Box<Profile>,
) -> Result<()>
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 notificationuser
- the user doing this
sourcepub async fn get_warning(&self, id: String) -> Result<Warning>
pub async fn get_warning(&self, id: String) -> Result<Warning>
sourcepub async fn get_warnings_by_recipient(
&self,
recipient: String,
user: Box<Profile>,
) -> Result<Vec<Warning>>
pub async fn get_warnings_by_recipient( &self, recipient: String, user: Box<Profile>, ) -> Result<Vec<Warning>>
sourcepub async fn create_warning(
&self,
props: WarningCreate,
user: Box<Profile>,
) -> Result<()>
pub async fn create_warning( &self, props: WarningCreate, user: Box<Profile>, ) -> Result<()>
sourcepub async fn delete_warning(&self, id: String, user: Box<Profile>) -> Result<()>
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 warninguser
- the user doing this
sourcepub async fn get_ipban_by_ip(&self, ip: String) -> Result<IpBan>
pub async fn get_ipban_by_ip(&self, ip: String) -> Result<IpBan>
sourcepub async fn create_ipban(
&self,
props: IpBanCreate,
user: Box<Profile>,
) -> Result<()>
pub async fn create_ipban( &self, props: IpBanCreate, user: Box<Profile>, ) -> Result<()>
sourcepub async fn get_user_relationship(
&self,
user: String,
other: String,
) -> (RelationshipStatus, String, String)
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 userother
- the ID of the second user
sourcepub async fn set_user_relationship_status(
&self,
one: String,
two: String,
status: RelationshipStatus,
disable_notifications: bool,
) -> Result<()>
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 usertwo
- the ID of the second userstatus
- the new relationship status, setting to “Unknown” will remove the relationshipdisable_notifications
sourcepub async fn get_user_relationships(
&self,
user: String,
) -> Result<Vec<(Box<Profile>, RelationshipStatus)>>
pub async fn get_user_relationships( &self, user: String, ) -> Result<Vec<(Box<Profile>, RelationshipStatus)>>
sourcepub async fn get_user_relationships_of_status(
&self,
user: String,
status: RelationshipStatus,
) -> Result<Vec<(Box<Profile>, RelationshipStatus)>>
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
sourcepub async fn get_user_participating_relationships_of_status(
&self,
user: String,
status: RelationshipStatus,
) -> Result<Vec<(Box<Profile>, Box<Profile>)>>
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
sourcepub async fn get_user_participating_relationships_of_status_paginated(
&self,
user: String,
status: RelationshipStatus,
page: i32,
) -> Result<Vec<(Box<Profile>, Box<Profile>)>>
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
sourcepub async fn get_friendship_count_by_user(&self, id: String) -> usize
pub async fn get_friendship_count_by_user(&self, id: String) -> usize
sourcepub async fn get_ipblock(&self, id: String) -> Result<IpBlock>
pub async fn get_ipblock(&self, id: String) -> Result<IpBlock>
sourcepub async fn get_ipblocks(&self, query_user: String) -> Result<Vec<IpBlock>>
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
sourcepub async fn create_ipblock(
&self,
props: IpBlockCreate,
user: Box<Profile>,
) -> Result<()>
pub async fn create_ipblock( &self, props: IpBlockCreate, user: Box<Profile>, ) -> Result<()>
sourcepub async fn get_mail_by_recipient_paginated(
&self,
recipient: String,
page: i32,
) -> Result<Vec<(Mail, Box<Profile>)>>
pub async fn get_mail_by_recipient_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<(Mail, Box<Profile>)>>
sourcepub async fn get_mail_by_recipient_sent_paginated(
&self,
recipient: String,
page: i32,
) -> Result<Vec<(Mail, Box<Profile>)>>
pub async fn get_mail_by_recipient_sent_paginated( &self, recipient: String, page: i32, ) -> Result<Vec<(Mail, Box<Profile>)>>
sourcepub async fn create_mail(
&self,
props: MailCreate,
author: String,
) -> Result<Mail>
pub async fn create_mail( &self, props: MailCreate, author: String, ) -> Result<Mail>
sourcepub async fn delete_mail(&self, id: String, user: Box<Profile>) -> Result<()>
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 mailuser
- the user doing this
sourcepub async fn update_mail_state(
&self,
id: String,
state: MailState,
user: Box<Profile>,
) -> Result<()>
pub async fn update_mail_state( &self, id: String, state: MailState, user: Box<Profile>, ) -> Result<()>
sourcepub async fn gimme_label(
&self,
res: HashMap<String, String>,
) -> Result<UserLabel>
pub async fn gimme_label( &self, res: HashMap<String, String>, ) -> Result<UserLabel>
Get a UserLabel
from a database result
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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