class CQL::Performance::SQLFormatter

Overview

Centralized SQL formatter with colorization support

Included Modules

Defined in:

performance/sql_formatter.cr

Constant Summary

QUOTE_BYTES = {'\''.ord.to_u8, '"'.ord.to_u8}
SQL_KEYWORDS = { dml: ["SELECT", "INSERT", "UPDATE", "DELETE", "FROM", "INTO", "SET", "VALUES", "WHERE"] of ::String, ddl: ["CREATE", "ALTER", "DROP", "TABLE", "INDEX", "VIEW"] of ::String, joins: ["INNER", "LEFT", "RIGHT", "FULL", "CROSS", "JOIN", "OUTER", "ON"] of ::String, clauses: ["ORDER", "BY", "GROUP", "HAVING", "LIMIT", "OFFSET", "DISTINCT", "AS"] of ::String, operators: ["AND", "OR", "NOT", "IN", "EXISTS", "BETWEEN", "LIKE", "ILIKE", "IS", "NULL"] of ::String, functions: ["COUNT", "SUM", "AVG", "MIN", "MAX", "COALESCE", "NULLIF", "CASE", "WHEN", "THEN", "ELSE", "END"] of ::String, types: ["INTEGER", "INT", "BIGINT", "VARCHAR", "TEXT", "BOOLEAN", "DATE", "TIMESTAMP", "JSON", "UUID"] of ::String, }

SQL keywords by category for colorization

Constructors

Instance Method Summary

Instance methods inherited from module CQL::Performance::ColorUtils

colorize_by_severity(text : String, severity : Symbol) : String colorize_by_severity, colorize_duration(duration : Time::Span, slow_threshold : Time::Span = 100.milliseconds, very_slow_threshold : Time::Span = 1.second) : String colorize_duration

Instance methods inherited from module CQL::Performance::TimingUtils

categorize_duration(duration : Time::Span, slow_threshold : Time::Span = 100.milliseconds, very_slow_threshold : Time::Span = 1.second) : Symbol categorize_duration, format_duration(duration : Time::Span) : String format_duration, measure_execution(&) measure_execution

Constructor Detail

def self.new(colorize_enabled : Bool = true, pretty_format : Bool = true, max_sql_length : Int32 = 500, max_param_length : Int32 = 50, include_params : Bool = false) #

[View source]

Instance Method Detail

def configure(colorize : Bool | Nil = nil, pretty : Bool | Nil = nil, max_sql : Int32 | Nil = nil, max_param : Int32 | Nil = nil, include_params : Bool | Nil = nil) #

Configure formatter


[View source]
def format(sql : String, params : Array(DB::Any) = [] of DB::Any, execution_time : Time::Span | Nil = nil, rows_affected : Int64 | Nil = nil, context : String | Nil = nil) : String #

Format SQL with optional colorization and pretty printing


[View source]
def format_params(params : Array(DB::Any)) : String #

Format parameters array


[View source]
def format_sql_only(sql : String) : String #

Format just the SQL without metadata


[View source]
def loggable_error(message : String) : String #

A driver's error message as it may appear in a log line: everything from the first to the last quote becomes '?' / "?" unless include_params is on.


[View source]
def loggable_params(params : Array(DB::Any)) : String | Nil #

The bound values as they may appear in a log line, or nil when they are hidden (include_params off) or there are none.


[View source]