Struct Database

Source
pub struct Database {
    pub base: StarterDatabase,
    pub config: ServerOptions,
    pub http: Client,
}
Expand description

Database connector

Fields§

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

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 async fn audit(&self, actor_id: &str, content: &str) -> Result<()>

Create a moderator audit log entry.

Source

pub async fn gimme_profile( &self, row: BTreeMap<String, String>, ) -> Result<Box<Profile>>

Get profile given the row data.

Source

fn is_digit(&self, input: &str) -> bool

Source

pub async fn get_profile_username(&self, id: &str) -> String

Get a profile’s username given its id.

Source

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

Fetch a profile correctly.

Source

pub async fn get_profile_by_hashed(&self, hashed: &str) -> 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: &str, ) -> 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: &str) -> 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( &self, username: &str, ) -> 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: &str) -> Result<Box<Profile>>

Get a user by their id.

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

pub fn validate_username(username: &str) -> Result<()>

Validate a username.

Source

pub async fn create_profile( &self, props: ProfileCreate, user_ip: &str, ) -> 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 async fn update_profile_question_count( &self, id: &str, count: usize, ) -> Result<()>

Update a profile count value.

§Arguments
  • id
  • count
Source

pub async fn update_profile_response_count( &self, id: &str, count: usize, ) -> Result<()>

Update a profile count value.

§Arguments
  • id
  • count
Source

pub async fn update_profile_inbox_count( &self, id: &str, count: usize, ) -> Result<()>

Update a profile count value.

§Arguments
  • id
  • count
Source

pub async fn update_profile_notification_count( &self, id: &str, count: usize, ) -> Result<()>

Update a profile count value.

§Arguments
  • id
  • count
Source

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

Update a Profile’s metadata by its id.

Source

pub async fn update_profile_tokens( &self, id: &str, 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: &str, badges: Vec<(String, String, String)>, ) -> Result<()>

Update a Profile’s badges by its id

Source

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

Update a Profile’s labels by its id

Update a Profile’s links by its id

Source

pub async fn update_profile_layout( &self, id: &str, layout: LayoutComponent, ) -> Result<()>

Update a Profile’s links by its id

Source

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

Update a Profile’s tier by its ID

Source

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

Update a Profile’s gid by its id

Source

pub async fn update_profile_coins(&self, id: &str, coins: i32) -> Result<()>

Update a Profile’s coins by its ID

§Arguments
  • coins - the amount to ADD to the existing coins value
Source

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

Update a Profile’s password by its name and password

Source

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

Update a Profile’s username by its id and password

Source

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

Delete a profile

VALIDATION SHOULD BE DONE BEFORE THIS!!

Source

pub async fn delete_profile_by_id(&self, id: &str) -> 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: &str, following: &str, ) -> Result<UserFollow>

Get an existing UserFollow

§Arguments:
  • user
  • following
Source

pub async fn get_followers( &self, user: &str, ) -> 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: &str, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

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

§Arguments:
  • user
  • page
Source

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

Get the number of followers user has

§Arguments:
  • user
Source

pub async fn get_following( &self, user: &str, ) -> 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: &str, page: i32, ) -> Result<Vec<(UserFollow, Box<Profile>, Box<Profile>)>>

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

§Arguments:
  • user
  • page
Source

pub async fn get_following_count(&self, user: &str) -> 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: &str) -> Result<Notification>

Get an existing notification

§Arguments
  • id
Source

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

Get all notifications by their recipient

§Arguments
  • recipient
Source

pub async fn get_notification_count_by_recipient_cache( &self, recipient: &str, ) -> usize

Get the number of notifications by their recipient

§Arguments
  • recipient
Source

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

Get the number of notifications by their recipient

§Arguments
  • recipient
Source

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

Get all notifications by their recipient, 12 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: &str, 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: &str, 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: &str) -> Result<Warning>

Get an existing warning

§Arguments
  • id
Source

pub async fn get_warnings_by_recipient( &self, recipient: &str, 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: &str, 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: &str) -> Result<IpBan>

Get an existing IpBan

§Arguments
  • id
Source

pub async fn get_ipban_by_ip(&self, ip: &str) -> 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: &str, 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: &str, other: &str, ) -> (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: &str, two: &str, 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: &str, ) -> 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: &str, 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: &str, 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: &str, 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, 12 at a time

§Arguments
  • user
  • status
  • page
Source

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

Get the number of friends a user has

§Arguments
  • id
Source

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

Get an existing IpBlock

§Arguments
  • id
Source

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

Get an existing IpBlock by its IP and its user

§Arguments
  • ip
  • user
Source

pub async fn get_ipblocks(&self, query_user: &str) -> 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: &str, user: Box<Profile>) -> Result<()>

Delete an existing IpBlock

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

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

Get a UserLabel from a database result

Source

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

Get an existing label

§Arguments
  • id
Source

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

Create a new user label

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

pub async fn delete_label(&self, id: i64, author: Box<Profile>) -> Result<()>

Create a new user label

§Arguments
  • id - the ID of the label
  • author - the ID of the user creating the label
Source

pub async fn gimme_transaction( &self, row: BTreeMap<String, String>, ) -> Result<(Transaction, Option<Item>)>

Source

pub async fn get_transaction( &self, id: &str, ) -> Result<(Transaction, Option<Item>)>

Get an existing transaction

§Arguments
  • id
Source

pub async fn get_transaction_by_customer_item( &self, customer: &str, item: &str, ) -> Result<(Transaction, Option<Item>)>

Get an existing transaction given the customer and the item

§Arguments
  • user
  • item
Source

pub async fn get_transactions_by_customer_paginated( &self, user: &str, page: i32, ) -> Result<Vec<((Transaction, Option<Item>), Box<Profile>, Box<Profile>)>>

Get all transactions where the customer is the given user ID, 12 at a time

§Arguments
  • user
  • page
§Returns

Vec<(Transaction, Customer, Merchant)>

Source

pub async fn get_participating_transactions_paginated( &self, user: &str, page: i32, ) -> Result<Vec<((Transaction, Option<Item>), Box<Profile>, Box<Profile>)>>

Get all transactions by the given user ID, 12 at a time

§Arguments
  • user
  • page
§Returns

Vec<(Transaction, Customer, Merchant)>

Source

pub async fn create_transaction( &self, props: TransactionCreate, customer: &str, ) -> Result<Transaction>

Create a new transaction

§Arguments
  • props - TransactionCreate
  • customer - the user in the customer field of the transaction
Source

pub fn gimme_item(&self, row: BTreeMap<String, String>) -> Result<Item>

Source

pub async fn get_item(&self, id: &str) -> Result<Item>

Get an existing item

§Arguments
  • id
Source

pub async fn get_items_by_creator_paginated( &self, user: &str, page: i32, ) -> Result<Vec<(Item, Box<Profile>)>>

Get all items by their creator, 12 at a time

§Arguments
  • user
  • page
§Returns

Vec<(Item, Box<Profile>)>

Source

pub async fn get_items_by_creator_type_paginated( &self, user: &str, type: ItemType, page: i32, ) -> Result<Vec<(Item, Box<Profile>)>>

Get all items by their creator and type, 12 at a time

§Arguments
  • user
  • type
  • page
§Returns

Vec<(Item, Box<Profile>)>

Source

pub async fn get_items_by_status_searched_paginated( &self, status: ItemStatus, page: i32, search: &str, ) -> Result<Vec<(Item, Box<Profile>)>>

Get all items by their status, 12 at a time

§Arguments
  • user
  • page
§Returns

Vec<(Item, Box<Profile>)>

Source

pub async fn get_items_by_type_paginated( &self, type: ItemType, page: i32, ) -> Result<Vec<(Item, Box<Profile>)>>

Get all items by their type, 12 at a time

§Arguments
  • type
  • page
§Returns

Vec<(Item, Box<Profile>)>

Source

pub async fn create_item( &self, props: ItemCreate, creator: &str, ) -> Result<Item>

Create a new item

§Arguments
  • props - ItemCreate
  • creator - the user in the creator field of the item
Source

pub async fn update_item_status( &self, id: &str, status: ItemStatus, user: Box<Profile>, ) -> Result<()>

Update item status

§Arguments
Source

pub async fn update_item( &self, id: &str, props: ItemEdit, user: Box<Profile>, ) -> Result<()>

Update item fields

§Arguments
Source

pub async fn update_item_content( &self, id: &str, props: ItemEditContent, user: Box<Profile>, ) -> Result<()>

Update item content

§Arguments
Source

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

Delete an existing item

Items can only be deleted by their creator.

§Arguments
  • id - the ID of the item
  • user - the user doing this
Source

pub async fn update_profile_totp_secret( &self, id: &str, secret: &str, recovery: &Vec<String>, ) -> Result<()>

Update the profile’s TOTP secret.

Source

pub async fn enable_totp( &self, as_user: Box<Profile>, id: &str, ) -> Result<(String, String, Vec<String>)>

Enable TOTP for a profile.

§Returns

Result<(secret, qr base64)>

Source

pub fn check_totp(&self, ua: &Box<Profile>, code: &str) -> bool

Validate a given TOTP code for the given profile.

Source

pub fn generate_totp_recovery_codes() -> Vec<String>

Generate 8 random recovery codes for TOTP.

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 u8)

🔬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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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