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>
impl<'a, T: Columned> QueryBuilder<'a, T>
Sourcepub fn new() -> QueryBuilder<'a, T>
pub fn new() -> QueryBuilder<'a, T>
Create a new QueryBuilder.
Sourcepub fn set(self, key: T::WriteKeys, val: &'a (dyn ToSql + Sync)) -> Self
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.
Sourcepub fn where_eq(self, key: T::ReadKeys, val: &'a (dyn ToSql + Sync)) -> Self
pub fn where_eq(self, key: T::ReadKeys, val: &'a (dyn ToSql + Sync)) -> Self
Filter results where the provided column equals the value.
Sourcepub fn where_ne(self, key: T::ReadKeys, val: &'a (dyn ToSql + Sync)) -> Self
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.
Sourcepub fn force(self) -> Self
pub fn force(self) -> Self
By default, write operations without a “WHERE” clause will be rejected. Call this function to force it to work.
Sourcepub async fn get(
self,
db: &DatabaseConnection,
) -> Result<Option<T>, PostgresReadError>
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.
Sourcepub async fn select_all(
self,
db: &DatabaseConnection,
) -> Result<Vec<T>, PostgresReadError>
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.
Sourcepub async fn update_many(
self,
db: &DatabaseConnection,
) -> Result<Vec<T>, PostgresWriteError>
pub async fn update_many( self, db: &DatabaseConnection, ) -> Result<Vec<T>, PostgresWriteError>
Update rows and return all updated records.
Sourcepub async fn update_one(
self,
db: &DatabaseConnection,
) -> Result<Option<T>, PostgresWriteError>
pub async fn update_one( self, db: &DatabaseConnection, ) -> Result<Option<T>, PostgresWriteError>
Update row and return first updated record.
Sourcepub async fn delete(
&self,
db: &DatabaseConnection,
) -> Result<(), PostgresWriteError>
pub async fn delete( &self, db: &DatabaseConnection, ) -> Result<(), PostgresWriteError>
Delete rows matching the provided condition.