Shared helpers for SQL-based sources to inject filter conditions into queries.
Wraps the original query in a CTE and appends WHERE clauses. Each SQL source
calls this with its own quote_fn for identifier quoting.
Example
quote_fn = fn id -> ~s("#{id}") end
Lotus.SQL.FilterInjector.apply("SELECT * FROM users", [
%Lotus.Query.Filter{column: "region", op: :eq, value: "US"}
], quote_fn)
#=> ~s(WITH _base AS (SELECT * FROM users) SELECT * FROM _base WHERE "region" = 'US')
Summary
Functions
Wraps the given SQL in a CTE and appends WHERE clauses for each filter.
Quotes a value as a SQL literal, handling type-appropriate formatting.
Functions
@spec apply(String.t(), [Lotus.Query.Filter.t()], (String.t() -> String.t())) :: String.t()
Wraps the given SQL in a CTE and appends WHERE clauses for each filter.
quote_fn is a 1-arity function that quotes an identifier for the target database.
Returns the original SQL unchanged if filters is empty.
Quotes a value as a SQL literal, handling type-appropriate formatting.