pub struct QueryBuilder<D: Dialect> { /* private fields */ }Expand description
SQL query builder with dialect support.
Implementations§
Source§impl<D: Dialect> QueryBuilder<D>
impl<D: Dialect> QueryBuilder<D>
Sourcepub fn new(dialect: D, table: impl Into<String>) -> Self
pub fn new(dialect: D, table: impl Into<String>) -> Self
Create a new query builder for the given table.
§Panics
Panics if the table name is not a valid SQL identifier.
Sourcepub fn computed(
self,
alias: impl Into<String>,
expression: impl Into<String>,
) -> Self
pub fn computed( self, alias: impl Into<String>, expression: impl Into<String>, ) -> Self
Add a computed field to the SELECT clause.
§Example
.computed("full_name", "first_name || ' ' || last_name")
.computed("line_total", "quantity * price")§Panics
Panics if alias is not a valid SQL identifier or expression contains dangerous patterns (comments, semicolons, SQL keywords).
§Security
WARNING: Only use with trusted expressions from code, never with user input.
Sourcepub fn filter_expr(self, expr: FilterExpr) -> Self
pub fn filter_expr(self, expr: FilterExpr) -> Self
Set a compound filter expression (replaces simple filters for WHERE clause).
Sourcepub fn and(self, filters: Vec<FilterExpr>) -> Self
pub fn and(self, filters: Vec<FilterExpr>) -> Self
Add an AND compound filter.
Sourcepub fn or(self, filters: Vec<FilterExpr>) -> Self
pub fn or(self, filters: Vec<FilterExpr>) -> Self
Add an OR compound filter.
Sourcepub fn having(self, expr: FilterExpr) -> Self
pub fn having(self, expr: FilterExpr) -> Self
Add a HAVING clause (for filtering aggregated results).
Sourcepub fn page(self, page: u32, limit: u32) -> Self
pub fn page(self, page: u32, limit: u32) -> Self
Set pagination with page number (1-indexed) and limit.
Sourcepub fn limit_offset(self, limit: u32, offset: u32) -> Self
pub fn limit_offset(self, limit: u32, offset: u32) -> Self
Set explicit limit and offset.
Sourcepub fn after_cursor(self, cursor: impl IntoCursor) -> Self
pub fn after_cursor(self, cursor: impl IntoCursor) -> Self
Paginate after this cursor (forward pagination).
This method accepts flexible input types for great DX:
&Cursor- when you have an already-parsed cursor&str- automatically decodes the base64 cursorOption<&str>- perfect forreq.query("after")results
If the cursor is invalid or None, it’s silently ignored.
This makes it safe to pass req.query("after") directly.
Sourcepub fn before_cursor(self, cursor: impl IntoCursor) -> Self
pub fn before_cursor(self, cursor: impl IntoCursor) -> Self
Paginate before this cursor (backward pagination).
This method accepts flexible input types for great DX:
&Cursor- when you have an already-parsed cursor&str- automatically decodes the base64 cursorOption<&str>- perfect forreq.query("before")results
If the cursor is invalid or None, it’s silently ignored.
Sourcepub fn build(self) -> QueryResult
pub fn build(self) -> QueryResult
Build the SQL query and parameters.