Skip to main content

GenericWhereGenerator

Struct GenericWhereGenerator 

Source
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:

  • GenericWhereGenerator is not Sync — 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>

Source

pub const fn new(dialect: D) -> Self

Create a new generator for the given dialect.

Source

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.

Source

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.

Source

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.

These impl blocks expose the same new() / with_indexed_columns() constructors that the old concrete struct had.

Source

pub const fn postgres_new() -> Self

Create a new PostgreSQL WHERE generator.

Source

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>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<D: SqlDialect> ExtendedOperatorHandler for GenericWhereGenerator<D>

Source§

fn generate_extended_sql( &self, operator: &ExtendedOperator, field_sql: &str, params: &mut Vec<Value>, ) -> Result<String>

Generate database-specific SQL for an extended operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more