QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<'a, T: Columned> { /* private fields */ }
Expand description

Builder used to easily construct simple SELECT, UPDATE and DELETE queries.

Implementations§

Source§

impl<'a, T: Columned> QueryBuilder<'a, T>

Source

pub fn new() -> QueryBuilder<'a, T>

Create a new QueryBuilder.

Source

pub fn set(self, key: T::WriteKeys, val: &'a (dyn ToSql + Sync)) -> Self

Set a column to a value for an upcoming update_one or update_many call.

Source

pub fn where_eq(self, key: T::ReadKeys, val: &'a (dyn ToSql + Sync)) -> Self

Filter results where the provided column equals the value.

Source

pub fn where_ne(self, key: T::ReadKeys, val: &'a (dyn ToSql + Sync)) -> Self

Filter results where the provided column does not equal the value.

Source

pub fn and(self) -> Self

Append an AND to the where clause.

Source

pub fn or(self) -> Self

Append an OR to the where clause.

Source

pub fn limit(self, val: i32) -> Self

Apply a limit

Source

pub fn offset(self, val: i32) -> Self

Apply an offset

Source

pub fn force(self) -> Self

By default, write operations without a “WHERE” clause will be rejected. Call this function to force it to work.

Source

pub async fn get( self, db: &DatabaseConnection, ) -> Result<Option<T>, PostgresReadError>

Select one will fetch an object from the database, and return an Option indicating whether it’s been found.

Source

pub async fn select_all( self, db: &DatabaseConnection, ) -> Result<Vec<T>, PostgresReadError>

Select all will fetch many objects from the database, and return a Vec. If no options are found, an empty Vec is returned.

Source

pub async fn update_many( self, db: &DatabaseConnection, ) -> Result<Vec<T>, PostgresWriteError>

Update rows and return all updated records.

Source

pub async fn update_one( self, db: &DatabaseConnection, ) -> Result<Option<T>, PostgresWriteError>

Update row and return first updated record.

Source

pub async fn delete( &self, db: &DatabaseConnection, ) -> Result<(), PostgresWriteError>

Delete rows matching the provided condition.

Trait Implementations§

Source§

impl<T: Columned> Default for QueryBuilder<'_, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for QueryBuilder<'a, T>

§

impl<'a, T> !RefUnwindSafe for QueryBuilder<'a, T>

§

impl<'a, T> Send for QueryBuilder<'a, T>
where <T as Columned>::ReadKeys: Send,

§

impl<'a, T> Sync for QueryBuilder<'a, T>
where <T as Columned>::ReadKeys: Sync,

§

impl<'a, T> Unpin for QueryBuilder<'a, T>
where <T as Columned>::ReadKeys: Unpin,

§

impl<'a, T> !UnwindSafe for QueryBuilder<'a, T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V