module

Krikri::PluginHelpers::PostgresqlQueryHeuristics

PostgresqlQueryHeuristics - pure logic for postgresql_query (see plugins/postgresql_query.cr): the changed-determination the real module performs on psycopg's statusmessage (it cannot see row counts for SELECT either - anything whose command tag is not SELECT/SHOW counts as a change), and psycopg %(name)s named-arg expansion down to positional binds (crystal-pg has no named-arg binding).

Class methods

bind_value(value : JSON::Any)

JSON::Any bind value down to crystal-pg's accepted set - JSON numbers are always Float64-or-Int64 from parse; keep everything else as its rendered string (matching the module's own string passthrough for arrays etc.).

Source
changed?(keyword : String, rows_affected : Int64) : Bool

The real module's rule, applied to the synthesized command tag: SELECT/SHOW never report changed; UPDATE/INSERT/DELETE report changed only when the affected-row count is non-zero (its "len(s) == 2/3" checks); anything else (CREATE, DROP, ALTER, TRUNCATE, SET, ...) always reports changed.

Source
expand_named_args(sql : String, named : Hash(String, JSON::Any)) : Tuple(String, Array(JSON::Any))

Rewrites psycopg-style %(name)s placeholders to $N binds and returns the values in that order. Names appearing repeatedly reuse their position. Raises on a name missing from the dict - real psycopg raises "KeyError" equivalently.

Source
leading_keyword(sql : String) : String

First significant SQL word, skipping line comments and block comments - the same leading-keyword view the real module's statusmessage check is driven by.

Source