rainbeam::database

Struct Database

pub struct Database {
    pub base: StarterDatabase,
    pub auth: Database,
    pub config: Config,
    langs: HashMap<String, LangFile>,
}
Expand description

Database connector

Fields§

§base: StarterDatabase§auth: Database§config: Config§langs: HashMap<String, LangFile>

Implementations§

§

impl Database

pub async fn new(opts: DatabaseOpts, auth: Database, config: Config) -> Database

pub async fn init(&self)

Init database

pub fn lang(&self, id: &str) -> LangFile

Get a LangFile given its ID

Returns net.rainbeam.langs:en-US if the given file cannot be found.

pub fn anonymous_tag(input: &str) -> (bool, String, String, String)

Get the tag of an anonymous username

§Returns

(is anonymous, tag, username, input)

pub fn create_anonymous(&self) -> (String, String)

Create an anonymous username

§Returns

("anonymous#" + tag, tag)

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

Fetch a profile correctly

pub fn parse_mentions(input: String) -> Vec<String>

Parse user mentions in a given input String

pub async fn get_profiles_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<Box<Profile>>, DatabaseError>

Get all profiles by a search query, 12 at a time

§Arguments
  • page
  • search

pub async fn create_data_export( &self, user: String, options: DataExportOptions, ) -> Result<DataExport, DatabaseError>

Export all data of the given user

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

Create a moderator audit log entry

pub fn get_question<'life_self, 'async_recursion>( &'life_self self, id: String, ) -> Pin<Box<dyn Future<Output = Result<Question, DatabaseError>> + Send + 'async_recursion>>
where 'life_self: 'async_recursion,

Get an existing question

§Arguments
  • id

pub async fn get_questions_by_recipient( &self, recipient: &str, ) -> Result<Vec<Question>, DatabaseError>

Get all questions by their recipient

§Arguments
  • recipient

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

Get the number of notifications by their recipient

§Arguments
  • recipient

pub async fn get_questions_by_author_paginated( &self, author: String, page: i32, ) -> Result<Vec<Question>, DatabaseError>

Get all questions by their author, 12 at a time

§Arguments
  • author
  • page

pub async fn get_global_questions_by_author( &self, author: &str, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all global questions by their author

§Arguments
  • author

pub async fn get_global_questions_by_author_paginated( &self, author: String, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all global questions by their author, 20 at a time

§Arguments
  • author
  • page

pub async fn get_global_questions_by_author_searched_paginated( &self, author: String, search: String, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all global questions by their author and a search query, 12 at a time

§Arguments
  • author
  • search
  • page

pub async fn get_global_questions_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all global questions by a search query, 12 at a time

§Arguments
  • page
  • search

pub async fn get_global_questions_by_following_paginated( &self, user: &str, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get global questions from people user is following, 12 at a time

§Arguments
  • user
  • page

pub async fn get_global_questions_paginated( &self, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all global questions, 12 at a time

§Arguments
  • page

pub async fn get_global_questions_count_by_author(&self, author: &str) -> usize

Get the number of global questions by their author

§Arguments
  • author

pub async fn get_questions_by_author( &self, author: String, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>

Get all questions by their author

§Arguments
  • author

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

Get the number of responses by their question

§Arguments
  • id

pub fn create_question<'life_self, 'async_recursion>( &'life_self self, props: QuestionCreate, author: String, ip: String, ) -> Pin<Box<dyn Future<Output = Result<String, DatabaseError>> + Send + 'async_recursion>>
where 'life_self: 'async_recursion,

Create a new question

§Arguments
  • props - QuestionCreate
  • author - the ID of the user creating the question
  • ip - author IP

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

Delete an existing question

Questions can only be deleted by their recipient or the user that asked them.

§Arguments
  • id - the ID of the question
  • user - the user doing this

pub async fn delete_questions_by_recipient( &self, recipient: &str, user: Box<Profile>, ) -> Result<(), DatabaseError>

Delete all questions by their recipient

§Arguments
  • recipient
  • user

pub async fn gimme_response( &self, res: BTreeMap<String, String>, ) -> Result<(Question, QuestionResponse, usize, usize), DatabaseError>

Get a response from a database result

pub async fn gimme_short_response( &self, res: BTreeMap<String, String>, ) -> Result<QuestionResponse, DatabaseError>

Get a (short) response from a database result

pub async fn get_response( &self, id: String, ) -> Result<(Question, QuestionResponse, usize, usize), DatabaseError>

Get an existing response

§Arguments
  • id

pub async fn get_response_short( &self, id: String, ) -> Result<QuestionResponse, DatabaseError>

Get an existing response (short)

This method is only for when we need a response and not its question and extra information.

§Arguments
  • id

pub async fn get_response_by_question_and_author( &self, question: &str, author: &str, ) -> Result<(Question, QuestionResponse, usize, usize), DatabaseError>

Get an existing response by the question ID and response author

§Arguments
  • question
  • author

pub async fn get_posts_paginated( &self, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all posts, 12 at a time

§Arguments
  • page

pub async fn get_posts_by_following_paginated( &self, page: i32, user: &str, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all posts from users the user is following, 12 at a time

§Arguments
  • page
  • user

pub async fn get_posts_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses, 12 at a time, matching search query

§Arguments
  • page
  • search

pub async fn get_responses_paginated( &self, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses, 12 at a time

§Arguments
  • page

pub async fn get_responses_by_author( &self, author: &str, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their author

§Arguments
  • author

pub async fn get_responses_by_author_paginated( &self, author: String, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their author, 12 at a time

§Arguments
  • author

pub async fn get_responses_by_author_searched_paginated( &self, author: String, search: String, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their author and content search, 12 at a time

§Arguments
  • author

pub async fn get_responses_by_author_tagged_paginated( &self, author: String, tag: String, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their author and tag, 12 at a time

§Arguments
  • author
  • tag

pub async fn get_responses_tagged_paginated( &self, tag: String, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their tag, 12 at a time

§Arguments
  • author
  • tag

pub async fn get_response_count_by_author(&self, author: &str) -> usize

Get the number of responses by their author

§Arguments
  • author

pub async fn get_responses_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses, 12 at a time, matching search query

§Arguments
  • page
  • search

pub async fn get_responses_by_following_paginated( &self, user: &str, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get 50 responses from people user is following

§Arguments
  • user

pub async fn get_responses_by_question( &self, id: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get all responses by their question ID

§Arguments
  • id

pub async fn create_response( &self, props: ResponseCreate, author: String, ) -> Result<QuestionResponse, DatabaseError>

Create a new response

Responses can only be created for questions where recipient matches the given author

§Arguments
  • props - ResponseCreate
  • author - the ID of the user creating the response

pub async fn update_response_reaction_count( &self, id: String, count: usize, ) -> Result<(), DatabaseError>

Update an existing response’s reaction count

§Arguments
  • id
  • count

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

Update an existing response’s content

§Arguments
  • id
  • content
  • user - the user doing this

pub async fn update_response_tags( &self, id: String, tags: Vec<String>, user: Box<Profile>, ) -> Result<(), DatabaseError>

Update an existing response’s tags

§Arguments
  • id
  • tags
  • user - the user doing this

pub async fn update_response_tags_multiple( &self, ids: Vec<String>, tags: Vec<String>, user: Box<Profile>, ) -> Result<(), DatabaseError>

Update the tags of multiple responses. All responses MUST be created by the same user.

§Arguments
  • ids
  • tags
  • user - the user doing this

pub async fn delete_response_multiple( &self, ids: Vec<String>, user: Box<Profile>, ) -> Result<(), DatabaseError>

Delete multiple responses. All responses MUST be created by the same user.

§Arguments
  • ids
  • user - the user doing this

pub async fn update_response_context( &self, id: String, context: ResponseContext, user: Box<Profile>, ) -> Result<(), DatabaseError>

Update an existing response’s context

§Arguments
  • id
  • context
  • user - the user doing this

pub async fn delete_response( &self, id: String, user: Box<Profile>, save_question: bool, ) -> Result<(), DatabaseError>

Delete an existing response

Responses can only be deleted by their author.

§Arguments
  • id - the ID of the response
  • user - the user doing this
  • save_question - if we should not delete the question too

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

Return a response’s question to the inbox and delete the response

§Arguments
  • id
  • user - the user doing this

pub fn get_comment<'life_self, 'async_recursion>( &'life_self self, id: String, recurse: bool, ) -> Pin<Box<dyn Future<Output = Result<(ResponseComment, usize, usize), DatabaseError>> + Send + 'async_recursion>>
where 'life_self: 'async_recursion,

Get an existing comment

§Arguments
  • id
  • recurse - should be FALSE when fetching counts to prevent a stack overflow

pub async fn get_comments_by_response( &self, id: String, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>

Get all comments by their response ID

§Arguments
  • id

pub async fn get_comments_by_response_paginated( &self, id: String, page: i32, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>

Get all comments by their response ID, 12 at a time

§Arguments
  • id

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

Get the number of comments by their response ID

§Arguments
  • id

pub async fn get_comments_by_author( &self, user: String, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>

Get all comments by their author ID

§Arguments
  • user

pub async fn get_comments_by_author_paginated( &self, user: String, page: i32, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>

Get all comments by their author ID (paginated by 25)

§Arguments
  • user
  • page

pub fn get_replies_by_comment<'life_self, 'async_recursion>( &'life_self self, id: String, recurse: bool, ) -> Pin<Box<dyn Future<Output = Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>> + Send + 'async_recursion>>
where 'life_self: 'async_recursion,

Get all replies by their comment ID

§Arguments
  • id
  • recurse - should be FALSE when fetching counts to prevent a stack overflow

pub async fn get_replies_by_comment_paginated( &self, id: String, page: i32, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>

Get all replies by their comment ID, 12 at a time

§Arguments
  • id

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

Get the number of replies by their comment ID

§Arguments
  • id

pub async fn create_comment( &self, props: CommentCreate, author: String, ip: String, ) -> Result<(), DatabaseError>

Create a new comment

Comments can only be created by non-anonymous users.

§Arguments
  • props - CommentCreate
  • author - the ID of the user creating the comment
  • ip - the IP address of the user creating the comment

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

Update an existing comment’s content

§Arguments
  • id
  • content
  • user - the user doing this

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

Delete an existing comment

Comments can only be deleted by their author.

§Arguments
  • id - the ID of the comment
  • user - the user doing this

pub async fn get_reaction( &self, user: String, asset: String, ) -> Result<Reaction, DatabaseError>

Get an existing reaction

§Arguments
  • user - the ID of the user
  • asset - the ID of the asset

pub async fn get_reactions_by_asset( &self, id: String, ) -> Result<Vec<Reaction>, DatabaseError>

Get all reactions by their asset ID

§Arguments
  • asset

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

Get the number of reactions by their asset ID

§Arguments
  • id

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

Create a new reaction

Reactions can only be created by non-anonymous users.

§Arguments
  • id - the ID of the asset
  • author - the user creating the reaction

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

Delete an existing reaction

Reactions can only be deleted by their author.

§Arguments
  • id - the ID of the reaction
  • user - the user doing this

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

Delete all reactions by their asset

§Arguments
  • id - the ID of the asset

pub async fn get_chat( &self, id: String, ) -> Result<(Chat, Vec<Box<Profile>>), DatabaseError>

Get an existing chat

§Arguments
  • id

pub async fn get_chat_by_users( &self, users_list: Vec<String>, ) -> Result<Chat, DatabaseError>

Get an existing chat

§Arguments
  • id

pub async fn get_chats_for_user( &self, id: &str, ) -> Result<Vec<(Chat, Vec<Box<Profile>>)>, DatabaseError>

Get all chats the given user ID is in

§Arguments
  • id - the ID of the user

pub async fn create_chat( &self, user1: String, user2: String, ) -> Result<Chat, DatabaseError>

Create a new chat

Chats can only be created by non-anonymous users.

§Arguments
  • user1 - the ID of the chat creator
  • user2 - the ID of the first chat member (NOT the creator)

pub async fn leave_chat( &self, id: String, user: String, ) -> Result<(), DatabaseError>

Leave an existing chat

Chats are deleted once the last member leaves

§Arguments
  • id - the ID of the chat
  • user - the ID of the user doing this

pub async fn update_chat_name( &self, props: ChatNameEdit, user: String, ) -> Result<(), DatabaseError>

Update an existing chat’s name

§Arguments

pub async fn add_friend_to_chat( &self, props: ChatAdd, user: String, ) -> Result<(), DatabaseError>

Add a friend to an existing chat

§Arguments

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

Get an existing message

§Arguments
  • id

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

Get the last message sent in a chat

§Arguments
  • id

pub async fn get_messages_by_user( &self, id: String, ) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>

Get all messages by their chat

§Arguments
  • id Get all messages by their author
§Arguments
  • id - user id

pub async fn get_messages_by_chat_paginated( &self, id: String, page: i32, ) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>

Get all messages by their chat, 50 at a time

§Arguments
  • id
  • page

pub async fn create_message( &self, props: MessageCreate, author: String, ) -> Result<Message, DatabaseError>

Create a new message

Messages can only be created by non-anonymous users.

§Arguments
  • props - MessageCreate
  • author - the ID of the user creating the message

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

Update an existing message’s content

§Arguments
  • id
  • content
  • user - the user doing this

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

Delete an existing message

Messages can only be deleted by their author.

§Arguments
  • id - the ID of the message
  • user - the user doing this

pub async fn get_top_reacted_responses( &self, cutoff: u128, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>

Get the top reacted-to responses (from the cutoff).

§Arguments
  • cutoff

pub async fn get_top_askers( &self, ) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>

Get the top “askers” (people who ask questions).

§Arguments
  • cutoff

pub async fn get_top_responders( &self, ) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>

Get the profiles with the most responses.

§Arguments
  • cutoff

Trait Implementations§

§

impl Clone for Database

§

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