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_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));Trait Implementations§
Source§impl<D: SqlDialect + Default> Default for GenericWhereGenerator<D>
impl<D: SqlDialect + Default> Default for GenericWhereGenerator<D>
Source§impl<D: SqlDialect> ExtendedOperatorHandler for GenericWhereGenerator<D>
impl<D: SqlDialect> ExtendedOperatorHandler for GenericWhereGenerator<D>
Source§fn generate_extended_sql(
&self,
operator: &ExtendedOperator,
field_sql: &str,
params: &mut Vec<Value>,
) -> Result<String>
fn generate_extended_sql( &self, operator: &ExtendedOperator, field_sql: &str, params: &mut Vec<Value>, ) -> Result<String>
Auto Trait Implementations§
impl<D> !Freeze for GenericWhereGenerator<D>
impl<D> !RefUnwindSafe for GenericWhereGenerator<D>
impl<D> Send for GenericWhereGenerator<D>
impl<D> !Sync for GenericWhereGenerator<D>
impl<D> Unpin for GenericWhereGenerator<D>where
D: Unpin,
impl<D> UnsafeUnpin for GenericWhereGenerator<D>where
D: UnsafeUnpin,
impl<D> UnwindSafe for GenericWhereGenerator<D>where
D: UnwindSafe,
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
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>
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>
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