pub struct GenericWhereGenerator<D: SqlDialect> { /* private fields */ }Expand description
Generic WHERE clause SQL generator.
Replaces PostgresWhereGenerator, MySqlWhereGenerator,
SqliteWhereGenerator, and SqlServerWhereGenerator — all dialect-specific
primitives are delegated to D: SqlDialect.
§Interior mutability
The parameter counter uses Cell<usize> (via ParamCounter). This is
safe because:
GenericWhereGeneratoris notSync— no concurrent access is possible.generate()resets the counter before every call.
§Example
use fraiseql_db::dialect::PostgresDialect;
use fraiseql_db::where_generator::GenericWhereGenerator;
use fraiseql_db::{WhereClause, WhereOperator};
use serde_json::json;
let gen = GenericWhereGenerator::new(PostgresDialect);
let clause = WhereClause::Field {
path: vec!["email".to_string()],
operator: WhereOperator::Eq,
value: json!("alice@example.com"),
};
let (sql, params) = gen.generate(&clause).unwrap();
assert_eq!(sql, "data->>'email' = $1");Implementations§
Source§impl<D: SqlDialect> GenericWhereGenerator<D>
impl<D: SqlDialect> GenericWhereGenerator<D>
Sourcepub fn with_indexed_columns(self, cols: Arc<HashSet<String>>) -> Self
pub fn with_indexed_columns(self, cols: Arc<HashSet<String>>) -> Self
Attach an indexed-columns set (PostgreSQL optimisation).
When a WHERE path matches a column name in this set, the generator
emits "col_name" = $N instead of data->>'col_name' = $N.
Sourcepub fn generate(&self, clause: &WhereClause) -> Result<(String, Vec<Value>)>
pub fn generate(&self, clause: &WhereClause) -> Result<(String, Vec<Value>)>
Generate SQL WHERE clause starting parameter numbering at 1.
§Errors
Returns FraiseQLError::Validation if the clause uses an operator
not supported by the dialect.
Sourcepub fn generate_with_hierarchy(
&self,
clause: &WhereClause,
hierarchy_ctx: &HierarchyContext,
) -> Result<(String, Vec<Value>)>
pub fn generate_with_hierarchy( &self, clause: &WhereClause, hierarchy_ctx: &HierarchyContext, ) -> Result<(String, Vec<Value>)>
Generate SQL WHERE clause with hierarchy context for ID-based ltree operators.
The hierarchy_ctx provides metadata (table, path_column, fk_column)
needed by DescendantOfId / AncestorOfId operators to generate the
correct subquery SQL.
§Errors
Returns FraiseQLError::Validation if the clause uses an unsupported
operator or the hierarchy context is missing for an ID-based operator.
Sourcepub fn generate_with_param_offset(
&self,
clause: &WhereClause,
offset: usize,
) -> Result<(String, Vec<Value>)>
pub fn generate_with_param_offset( &self, clause: &WhereClause, offset: usize, ) -> Result<(String, Vec<Value>)>
Generate SQL WHERE clause with parameter numbering starting after offset.
Use when the WHERE clause is appended to a query that already has bound parameters (e.g. cursor values in relay pagination).
§Errors
Returns FraiseQLError::Validation if the clause uses an unsupported
operator.
Source§impl GenericWhereGenerator<PostgresDialect>
Constructor compatibility shim for PostgresWhereGenerator.
impl GenericWhereGenerator<PostgresDialect>
Constructor compatibility shim for PostgresWhereGenerator.
These impl blocks expose the same new() / with_indexed_columns()
constructors that the old concrete struct had.
Sourcepub const fn postgres_new() -> Self
pub const fn postgres_new() -> Self
Create a new PostgreSQL WHERE generator.
Sourcepub fn postgres_with_indexed_columns(
indexed_columns: Arc<HashSet<String>>,
) -> Self
pub fn postgres_with_indexed_columns( indexed_columns: Arc<HashSet<String>>, ) -> Self
Create a new PostgreSQL WHERE generator with indexed columns for a view.
When indexed columns are provided, the generator uses them instead of JSONB extraction for nested paths that have corresponding indexed columns.
§Arguments
indexed_columns- Set of indexed column names for the current view
§Example
use fraiseql_db::postgres::PostgresWhereGenerator;
use std::collections::HashSet;
use std::sync::Arc;
let mut columns = HashSet::new();
columns.insert("items__product__category__code".to_string());
let generator = PostgresWhereGenerator::postgres_with_indexed_columns(Arc::new(columns));