Lotus.Source.Adapters.Ecto.SQL.Transformer (Lotus v1.0.0)

Copy Markdown View Source

Shared SQL transformation utilities used by dialect implementations.

Dialect modules call these helpers from their transform_statement/1 callback to normalize SQL before variables are bound.

Summary

Functions

Strip single-quoted wrappers from simple variable placeholders.

Transform PostgreSQL INTERVAL syntax with variable placeholders.

Transform quoted wildcard patterns around variable placeholders into concatenation expressions using the given operator.

Functions

strip_quoted_variables(sql)

@spec strip_quoted_variables(String.t()) :: String.t()

Strip single-quoted wrappers from simple variable placeholders.

Converts '{{email}}'{{email}} but leaves complex expressions like '%{{q}}%' unchanged (those are handled by wildcard transforms).

transform_pg_intervals(sql)

@spec transform_pg_intervals(String.t()) :: String.t()

Transform PostgreSQL INTERVAL syntax with variable placeholders.

Handles patterns like:

  • INTERVAL {{var}}({{var}}::text)::interval
  • INTERVAL '{{var}}'CAST({{var}} AS interval)
  • INTERVAL '{{n}} days'make_interval(days => ({{n}})::integer)

transform_wildcards(sql, operator \\ :pipe)

@spec transform_wildcards(String.t(), :pipe | :concat_fn) :: String.t()

Transform quoted wildcard patterns around variable placeholders into concatenation expressions using the given operator.

Operators

  • :pipe — uses || (Postgres, SQLite, default SQL)
  • :concat_fn — uses CONCAT() (MySQL)

Examples

transform_wildcards("'%{{q}}%'", :pipe)
# => "'%' || {{q}} || '%'"

transform_wildcards("'%{{q}}%'", :concat_fn)
# => "CONCAT('%', {{q}}, '%')"