Struct puffer::db::Database

source ·
pub struct Database {
    pub base: StarterDatabase,
    pub auth: AuthDatabase,
    pub logs: LogDatabase,
}

Fields§

§base: StarterDatabase§auth: AuthDatabase§logs: LogDatabase

Implementations§

source§

impl Database

source

pub async fn new(opts: DatabaseOpts) -> Database

source

pub async fn init(&self)

source

pub async fn get_user_by_hashed( &self, hashed: String ) -> DefaultReturn<Option<FullUser<String>>>

Get a user by their hashed ID

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

pub async fn get_user_by_unhashed( &self, unhashed: String ) -> DefaultReturn<Option<FullUser<String>>>

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

Calls Database::get_user_by_unhashed_st() if user is invalid.

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

pub async fn get_user_by_unhashed_st( &self, unhashed: String ) -> DefaultReturn<Option<FullUser<String>>>

Get a user by their unhashed secondary token

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

pub async fn get_user_by_username( &self, username: String ) -> DefaultReturn<Option<FullUser<String>>>

Get a user by their username

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

pub async fn get_level_by_role( &self, name: String ) -> DefaultReturn<RoleLevelLog>

Get a RoleLevel by its name

Arguments:
  • name - String of the level’s role name
source

pub async fn get_board_by_name( &self, url: String ) -> DefaultReturn<Option<Board<String>>>

Get a Board by its name

Arguments:
  • url - board name
source

pub async fn get_boards( &self, offset: Option<i32> ) -> DefaultReturn<Option<Vec<BoardIdentifier>>>

Get public Boards

Arguments:
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_boards_by_tags( &self, tags: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<BoardIdentifier>>>

Get public Boards by their tags

Arguments:
  • tags - space separated list of tags, tags should use “_” instead of a space in their names, all tags should start with “+”
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_board_posts( &self, url: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get all posts in a Board by its name

Arguments:
  • url - board name
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_board_posts_by_tag( &self, url: String, tags: String, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get all posts in a Board by its name and their tags

Arguments:
  • url - board name
  • tags - space separated list of tags, tags should use “_” instead of a space in their names, all tags should start with “+”
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_pinned_board_posts( &self, url: String ) -> DefaultReturn<Option<Vec<Log>>>

Get all pinned posts in a Board by its name

Arguments:
  • url - board name
source

pub async fn get_post_replies_limited( &self, id: String, run_existing_check: bool, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get all posts in a Board by its name that are replying to another BoardPostLog (limited form)

Arguments:
  • id - post id
  • run_existing_check - if we should check that the log exists first
source

pub async fn get_post_replies( &self, id: String, run_existing_check: bool ) -> DefaultReturn<Option<Vec<LogIdentifier>>>

Get all posts in a Board by its name that are replying to another BoardPostLog

  • only includes post id
Arguments:
  • id - post id
  • run_existing_check - if we should check that the log exists first
source

pub async fn get_boards_by_owner( &self, owner: String ) -> DefaultReturn<Option<Vec<BoardIdentifier>>>

Get all boards owned by a specific user

Arguments:
  • owner - String of the owner’s username
source

pub async fn fetch_most_recent_posts( &self, offset: Option<i32> ) -> DefaultReturn<Option<Vec<Log>>>

Get most recent posts from all Boards

Arguments:
  • offset - optional value representing the SQL fetch offset
source

pub async fn get_user_posts_count(&self, user: String) -> DefaultReturn<usize>

Get the amount of posts a user has created in all boards

Arguments:
  • user - username of user to check
source

pub async fn create_board( &self, props: &mut Board<String>, as_user: Option<String> ) -> DefaultReturn<Option<Board<String>>>

Create a new Board given various properties

Arguments:
  • props - Board<String>
  • as_user - The ID of the user creating the board
source

pub async fn create_board_post( &self, props: &mut BoardPostLog, as_user: Option<String>, as_role: Option<RoleLevel> ) -> DefaultReturn<Option<String>>

Create a new post in a given Board

Arguments:
  • props - BoardPostLog
  • as_user - The ID of the user creating the post
source

pub async fn edit_board_metadata_by_name( &self, name: String, metadata: BoardMetadata, edit_as: Option<String> ) -> DefaultReturn<Option<String>>

Update a Board’s metadata by its custom_url

source

pub async fn delete_board(&self, name: String) -> DefaultReturn<Option<String>>

Delete a board given its name

Arguments:
  • name - String of the board’s name

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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

§

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

§

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 Twhere 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