pub struct GenericWhereGenerator<D>where
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> GenericWhereGenerator<D>where
D: SqlDialect,
impl<D> GenericWhereGenerator<D>where
D: SqlDialect,
Sourcepub const fn new(dialect: D) -> GenericWhereGenerator<D>
pub const fn new(dialect: D) -> GenericWhereGenerator<D>
Create a new generator for the given dialect.
Sourcepub fn generate(
&self,
clause: &WhereClause,
) -> Result<(String, Vec<Value>), FraiseQLError>
pub fn generate( &self, clause: &WhereClause, ) -> Result<(String, Vec<Value>), FraiseQLError>
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>), FraiseQLError>
pub fn generate_with_param_offset( &self, clause: &WhereClause, offset: usize, ) -> Result<(String, Vec<Value>), FraiseQLError>
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.
This impl block exposes the new() constructor the old concrete struct had.
Sourcepub const fn postgres_new() -> GenericWhereGenerator<PostgresDialect>
pub const fn postgres_new() -> GenericWhereGenerator<PostgresDialect>
Create a new PostgreSQL WHERE generator.