Module: SqlGenius::Core::Ai::DialectHints

Extended by:
DialectHints
Included in:
DialectHints
Defined in:
lib/sql_genius/core/ai/dialect_hints.rb

Overview

Snippets injected into AI system prompts so the model generates SQL in the right dialect. Without these, prompts hardcode “MySQL” and tell the model to use backticks — which produces broken SQL on PostgreSQL (PG uses double quotes for identifiers and has no backtick syntax).

Instance Method Summary collapse

Instance Method Details

#identifier_quoting_rule(connection) ⇒ Object

Identifier-quoting rule string for inclusion in a numbered Rules list in a prompt. PG uses double quotes; MySQL/MariaDB uses backticks.



25
26
27
28
29
30
31
# File 'lib/sql_genius/core/ai/dialect_hints.rb', line 25

def identifier_quoting_rule(connection)
  if connection.server_version.postgresql?
    %(Use double quotes ("col_name") for case-sensitive identifiers; otherwise leave them bare.)
  else
    "Use backticks (`col_name`) for table and column names."
  end
end

#name_for(connection) ⇒ Object

Display name suitable for “You are a SQL assistant for a ##name_for database.” prompts.



15
16
17
18
19
20
# File 'lib/sql_genius/core/ai/dialect_hints.rb', line 15

def name_for(connection)
  case connection.server_version.dialect
  when :postgresql then "PostgreSQL"
  else "MySQL/MariaDB"
  end
end