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
impl Database
pub async fn new(opts: DatabaseOpts, auth: Database, config: Config) -> Database
pub async fn init(&self)
pub async fn init(&self)
Init database
pub fn lang(&self, id: &str) -> LangFile
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 create_anonymous(&self) -> (String, String)
pub fn create_anonymous(&self) -> (String, String)
pub async fn get_profile<T>(&self, id: T) -> Result<Box<Profile>, DatabaseError>
pub async fn get_profile<T>(&self, id: T) -> Result<Box<Profile>, DatabaseError>
Fetch a profile correctly
pub fn parse_mentions(input: String) -> Vec<String>
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>
pub async fn get_profiles_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<Box<Profile>>, DatabaseError>
pub async fn create_data_export(
&self,
user: String,
options: DataExportOptions,
) -> Result<DataExport, DatabaseError>
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>
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,
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,
pub async fn get_questions_by_recipient(
&self,
recipient: &str,
) -> Result<Vec<Question>, DatabaseError>
pub async fn get_questions_by_recipient( &self, recipient: &str, ) -> Result<Vec<Question>, DatabaseError>
pub async fn get_inbox_count_by_recipient(&self, recipient: &str) -> usize
pub async fn get_inbox_count_by_recipient(&self, recipient: &str) -> usize
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>
pub async fn get_global_questions_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>
pub async fn get_global_questions_by_following_paginated(
&self,
user: &str,
page: i32,
) -> Result<Vec<(Question, usize, usize)>, DatabaseError>
pub async fn get_global_questions_by_following_paginated( &self, user: &str, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>
pub async fn get_global_questions_paginated(
&self,
page: i32,
) -> Result<Vec<(Question, usize, usize)>, DatabaseError>
pub async fn get_global_questions_paginated( &self, page: i32, ) -> Result<Vec<(Question, usize, usize)>, DatabaseError>
pub async fn get_response_count_by_question(&self, id: String) -> usize
pub async fn get_response_count_by_question(&self, id: String) -> usize
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,
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 questionip
- author IP
pub async fn delete_question(
&self,
id: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
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 questionuser
- the user doing this
pub async fn delete_questions_by_recipient(
&self,
recipient: &str,
user: Box<Profile>,
) -> Result<(), DatabaseError>
pub async fn delete_questions_by_recipient( &self, recipient: &str, user: Box<Profile>, ) -> Result<(), DatabaseError>
pub async fn gimme_response(
&self,
res: BTreeMap<String, String>,
) -> Result<(Question, QuestionResponse, usize, usize), DatabaseError>
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>
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>
pub async fn get_response( &self, id: String, ) -> Result<(Question, QuestionResponse, usize, usize), DatabaseError>
pub async fn get_response_short(
&self,
id: String,
) -> Result<QuestionResponse, DatabaseError>
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_posts_paginated(
&self,
page: i32,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_posts_paginated( &self, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_posts_by_following_paginated(
&self,
page: i32,
user: &str,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_posts_by_following_paginated( &self, page: i32, user: &str, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_posts_searched_paginated(
&self,
page: i32,
search: String,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_posts_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_paginated(
&self,
page: i32,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_paginated( &self, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_tagged_paginated(
&self,
tag: String,
page: i32,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_tagged_paginated( &self, tag: String, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_searched_paginated(
&self,
page: i32,
search: String,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_searched_paginated( &self, page: i32, search: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_by_following_paginated(
&self,
user: &str,
page: i32,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_by_following_paginated( &self, user: &str, page: i32, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_by_question(
&self,
id: String,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_responses_by_question( &self, id: String, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn create_response(
&self,
props: ResponseCreate,
author: String,
) -> Result<QuestionResponse, DatabaseError>
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>
pub async fn update_response_reaction_count( &self, id: String, count: usize, ) -> Result<(), DatabaseError>
pub async fn update_response_content(
&self,
id: String,
content: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
pub async fn update_response_content( &self, id: String, content: 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>
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>
pub async fn update_response_context( &self, id: String, context: ResponseContext, user: Box<Profile>, ) -> Result<(), DatabaseError>
pub async fn delete_response(
&self,
id: String,
user: Box<Profile>,
save_question: bool,
) -> Result<(), DatabaseError>
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 responseuser
- the user doing thissave_question
- if we should not delete the question too
pub async fn unsend_response(
&self,
id: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
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,
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>
pub async fn get_comments_by_response( &self, id: String, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>
pub async fn get_comments_by_response_paginated(
&self,
id: String,
page: i32,
) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>
pub async fn get_comments_by_response_paginated( &self, id: String, page: i32, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>
pub async fn get_comment_count_by_response(&self, id: String) -> usize
pub async fn get_comment_count_by_response(&self, id: String) -> usize
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,
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>
pub async fn get_replies_by_comment_paginated( &self, id: String, page: i32, ) -> Result<Vec<(ResponseComment, usize, usize)>, DatabaseError>
pub async fn get_reply_count_by_comment(&self, id: String) -> usize
pub async fn get_reply_count_by_comment(&self, id: String) -> usize
pub async fn create_comment(
&self,
props: CommentCreate,
author: String,
ip: String,
) -> Result<(), DatabaseError>
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 commentip
- 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>
pub async fn update_comment_content( &self, id: String, content: String, user: Box<Profile>, ) -> Result<(), DatabaseError>
pub async fn delete_comment(
&self,
id: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
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 commentuser
- the user doing this
pub async fn get_reaction(
&self,
user: String,
asset: String,
) -> Result<Reaction, DatabaseError>
pub async fn get_reaction( &self, user: String, asset: String, ) -> Result<Reaction, DatabaseError>
pub async fn get_reactions_by_asset(
&self,
id: String,
) -> Result<Vec<Reaction>, DatabaseError>
pub async fn get_reactions_by_asset( &self, id: String, ) -> Result<Vec<Reaction>, DatabaseError>
pub async fn get_reaction_count_by_asset(&self, id: String) -> usize
pub async fn get_reaction_count_by_asset(&self, id: String) -> usize
pub async fn create_reaction(
&self,
id: String,
author: Box<Profile>,
) -> Result<(), DatabaseError>
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 assetauthor
- the user creating the reaction
pub async fn delete_reaction(
&self,
id: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
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 reactionuser
- the user doing this
pub async fn clear_reactions(&self, id: String) -> Result<(), DatabaseError>
pub async fn clear_reactions(&self, id: String) -> Result<(), DatabaseError>
pub async fn get_chat_by_users(
&self,
users_list: Vec<String>,
) -> Result<Chat, DatabaseError>
pub async fn get_chat_by_users( &self, users_list: Vec<String>, ) -> Result<Chat, DatabaseError>
pub async fn get_chats_for_user(
&self,
id: &str,
) -> Result<Vec<(Chat, Vec<Box<Profile>>)>, DatabaseError>
pub async fn get_chats_for_user( &self, id: &str, ) -> Result<Vec<(Chat, Vec<Box<Profile>>)>, DatabaseError>
pub async fn create_chat(
&self,
user1: String,
user2: String,
) -> Result<Chat, DatabaseError>
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 creatoruser2
- the ID of the first chat member (NOT the creator)
pub async fn leave_chat(
&self,
id: String,
user: String,
) -> Result<(), DatabaseError>
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 chatuser
- the ID of the user doing this
pub async fn update_chat_name(
&self,
props: ChatNameEdit,
user: String,
) -> Result<(), DatabaseError>
pub async fn update_chat_name( &self, props: ChatNameEdit, user: String, ) -> Result<(), DatabaseError>
pub async fn add_friend_to_chat(
&self,
props: ChatAdd,
user: String,
) -> Result<(), DatabaseError>
pub async fn add_friend_to_chat( &self, props: ChatAdd, user: String, ) -> Result<(), DatabaseError>
Add a friend to an existing chat
§Arguments
props
-ChatNameEdit
user
- the ID of the user doing this
pub async fn get_message(
&self,
id: String,
) -> Result<(Message, Box<Profile>), DatabaseError>
pub async fn get_message( &self, id: String, ) -> Result<(Message, Box<Profile>), DatabaseError>
pub async fn get_last_message_in_chat(
&self,
id: String,
) -> Result<(Message, Box<Profile>), DatabaseError>
pub async fn get_last_message_in_chat( &self, id: String, ) -> Result<(Message, Box<Profile>), DatabaseError>
pub async fn get_messages_by_user(
&self,
id: String,
) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>
pub async fn get_messages_by_user( &self, id: String, ) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>
pub async fn get_messages_by_chat_paginated(
&self,
id: String,
page: i32,
) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>
pub async fn get_messages_by_chat_paginated( &self, id: String, page: i32, ) -> Result<Vec<(Message, Box<Profile>)>, DatabaseError>
pub async fn create_message(
&self,
props: MessageCreate,
author: String,
) -> Result<Message, DatabaseError>
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>
pub async fn edit_message( &self, id: String, content: String, user: Box<Profile>, ) -> Result<(), DatabaseError>
pub async fn delete_message(
&self,
id: String,
user: Box<Profile>,
) -> Result<(), DatabaseError>
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 messageuser
- the user doing this
pub async fn get_top_reacted_responses(
&self,
cutoff: u128,
) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_top_reacted_responses( &self, cutoff: u128, ) -> Result<Vec<(Question, QuestionResponse, usize, usize)>, DatabaseError>
pub async fn get_top_askers(
&self,
) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>
pub async fn get_top_askers( &self, ) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>
pub async fn get_top_responders(
&self,
) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>
pub async fn get_top_responders( &self, ) -> Result<Vec<(usize, Box<Profile>)>, DatabaseError>
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