pub struct QueryBuilder<'d> { /* private fields */ }Expand description
Builds parameterized SQL statements for a specific dialect.
§Usage
use fletch_orm::query_builder::{QueryBuilder, Order};
use fletch_orm::dialect::PostgresDialect;
use fletch_orm::filter::{Filter, Op};
let dialect = PostgresDialect;
let query = QueryBuilder::select(&dialect, "users")
.columns(&["id", "name", "email"])
.filter(Filter::new("name", Op::Eq, "Alice"))
.order_by("id", Order::Asc)
.limit(10)
.build();
assert_eq!(
query.sql,
"SELECT \"id\", \"name\", \"email\" FROM \"users\" WHERE \"name\" = $1 ORDER BY \"id\" ASC LIMIT 10"
);Implementations§
Source§impl<'d> QueryBuilder<'d>
impl<'d> QueryBuilder<'d>
Sourcepub fn columns(self, cols: &[&str]) -> Self
pub fn columns(self, cols: &[&str]) -> Self
Set the columns to select (SELECT) or insert into (INSERT).
Sourcepub fn set(self, column: &str, value: impl Into<Value>) -> Self
pub fn set(self, column: &str, value: impl Into<Value>) -> Self
Set a column value for INSERT or UPDATE operations.
Sourcepub fn returning(self, cols: &[&str]) -> Self
pub fn returning(self, cols: &[&str]) -> Self
Specify columns to return via RETURNING (Postgres/SQLite).
On MySQL, this is ignored; use LAST_INSERT_ID() instead.
Sourcepub fn build(self) -> BuiltQuery
pub fn build(self) -> BuiltQuery
Build the SQL query and return the SQL string with bind values.
Auto Trait Implementations§
impl<'d> !RefUnwindSafe for QueryBuilder<'d>
impl<'d> !UnwindSafe for QueryBuilder<'d>
impl<'d> Freeze for QueryBuilder<'d>
impl<'d> Send for QueryBuilder<'d>
impl<'d> Sync for QueryBuilder<'d>
impl<'d> Unpin for QueryBuilder<'d>
impl<'d> UnsafeUnpin for QueryBuilder<'d>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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