pub struct SqlBuilder { /* private fields */ }Expand description
Builds parameterized SQL queries safely.
All user-supplied values go through DuckDB’s parameter binding (? placeholders),
never through string interpolation. Methods return &mut Self for chaining.
Implementations§
Source§impl SqlBuilder
impl SqlBuilder
Sourcepub fn select(&mut self, cols: &[&str]) -> &mut Self
pub fn select(&mut self, cols: &[&str]) -> &mut Self
Set the columns to select (replaces the default *).
Sourcepub fn join(&mut self, clause: &str) -> &mut Self
pub fn join(&mut self, clause: &str) -> &mut Self
Add a JOIN clause.
The clause should be a full JOIN expression, e.g.
"JOIN sets s ON cards.setCode = s.code".
Sourcepub fn where_clause(&mut self, condition: &str, params: &[&str]) -> &mut Self
pub fn where_clause(&mut self, condition: &str, params: &[&str]) -> &mut Self
Add a WHERE condition with ? placeholders for each param.
The caller provides a condition using ? for each parameter value.
Parameters are appended in order.
Sourcepub fn where_like(&mut self, column: &str, value: &str) -> &mut Self
pub fn where_like(&mut self, column: &str, value: &str) -> &mut Self
Add a case-insensitive LIKE condition.
Generates: LOWER({column}) LIKE LOWER(?)
Sourcepub fn where_in(&mut self, column: &str, values: &[&str]) -> &mut Self
pub fn where_in(&mut self, column: &str, values: &[&str]) -> &mut Self
Add an IN condition with parameterized values.
Empty values list produces FALSE.
Sourcepub fn where_eq(&mut self, column: &str, value: &str) -> &mut Self
pub fn where_eq(&mut self, column: &str, value: &str) -> &mut Self
Add an equality condition: {column} = ?.
Sourcepub fn where_gte(&mut self, column: &str, value: &str) -> &mut Self
pub fn where_gte(&mut self, column: &str, value: &str) -> &mut Self
Add a greater-than-or-equal condition: {column} >= ?.
Sourcepub fn where_lte(&mut self, column: &str, value: &str) -> &mut Self
pub fn where_lte(&mut self, column: &str, value: &str) -> &mut Self
Add a less-than-or-equal condition: {column} <= ?.
Sourcepub fn where_regex(&mut self, column: &str, pattern: &str) -> &mut Self
pub fn where_regex(&mut self, column: &str, pattern: &str) -> &mut Self
Add a regex match condition using DuckDB’s regexp_matches.
Generates: regexp_matches({column}, ?)
Sourcepub fn where_fuzzy(
&mut self,
column: &str,
value: &str,
threshold: f64,
) -> &mut Self
pub fn where_fuzzy( &mut self, column: &str, value: &str, threshold: f64, ) -> &mut Self
Add a fuzzy string match condition using Jaro-Winkler similarity.
Generates: jaro_winkler_similarity({column}, ?) > {threshold}
The threshold must be between 0.0 and 1.0 (inclusive).
Sourcepub fn where_or(&mut self, conditions: &[(&str, &str)]) -> &mut Self
pub fn where_or(&mut self, conditions: &[(&str, &str)]) -> &mut Self
Add OR-combined conditions.
Each condition is a (sql_fragment, param_value) tuple where the fragment
uses ? as a placeholder.
§Example
use mtgjson_sdk::SqlBuilder;
let mut builder = SqlBuilder::new("cards");
builder.where_or(&[("name = ?", "Bolt"), ("name = ?", "Counter")]);
// -> WHERE (name = ? OR name = ?)Sourcepub fn having(&mut self, condition: &str, params: &[&str]) -> &mut Self
pub fn having(&mut self, condition: &str, params: &[&str]) -> &mut Self
Add a HAVING condition with ? placeholders.
Sourcepub fn order_by(&mut self, clauses: &[&str]) -> &mut Self
pub fn order_by(&mut self, clauses: &[&str]) -> &mut Self
Add ORDER BY clauses (e.g. "name ASC", "price DESC").