pub struct SelectBuilder { /* private fields */ }Expand description
Fluent builder for SELECT queries.
§Example
use oxisql_core::query::{SelectBuilder, SortDirection};
let q = SelectBuilder::new()
.columns(&["id", "name", "email"])
.from("users")
.where_eq("active", &true)
.order_by("name", Default::default())
.limit(20)
.offset(40)
.build();
assert_eq!(q.sql, "SELECT id, name, email FROM users WHERE active = $1 ORDER BY name ASC LIMIT 20 OFFSET 40");Implementations§
Source§impl SelectBuilder
impl SelectBuilder
Sourcepub fn columns(self, cols: &[&str]) -> Self
pub fn columns(self, cols: &[&str]) -> Self
Add columns to SELECT. Call multiple times or pass a slice.
Sourcepub fn where_raw(self, condition: &str) -> Self
pub fn where_raw(self, condition: &str) -> Self
Add a raw WHERE condition (e.g. "id > $1"). Call multiple times to AND them.
Sourcepub fn where_eq(self, col: &str, val: &dyn ToSqlValue) -> Self
pub fn where_eq(self, col: &str, val: &dyn ToSqlValue) -> Self
Add a WHERE col = $N condition, binding the value.
Sourcepub fn order_by(self, col: &str, dir: SortDirection) -> Self
pub fn order_by(self, col: &str, dir: SortDirection) -> Self
Add an ORDER BY clause.
Sourcepub fn build(self) -> BuiltQuery
pub fn build(self) -> BuiltQuery
Build the query into a BuiltQuery.
Trait Implementations§
Source§impl Clone for SelectBuilder
impl Clone for SelectBuilder
Source§fn clone(&self) -> SelectBuilder
fn clone(&self) -> SelectBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SelectBuilder
impl Debug for SelectBuilder
Source§impl Default for SelectBuilder
impl Default for SelectBuilder
Source§fn default() -> SelectBuilder
fn default() -> SelectBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SelectBuilder
impl RefUnwindSafe for SelectBuilder
impl Send for SelectBuilder
impl Sync for SelectBuilder
impl Unpin for SelectBuilder
impl UnsafeUnpin for SelectBuilder
impl UnwindSafe for SelectBuilder
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
Mutably borrows from an owned value. Read more