class
CQL::Performance::SQLFormatter
- CQL::Performance::SQLFormatter
- Reference
- Object
Overview
Centralized SQL formatter with colorization support
Included Modules
Defined in:
performance/sql_formatter.crConstant 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
-
#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
-
#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
-
#format_params(params : Array(DB::Any)) : String
Format parameters array
-
#format_sql_only(sql : String) : String
Format just the SQL without metadata
-
#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
'?'/"?"unlessinclude_paramsis on. -
#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_paramsoff) or there are none.
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
Instance Method Detail
Configure formatter
Format SQL with optional colorization and pretty printing
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.
The bound values as they may appear in a log line, or nil when they are
hidden (include_params off) or there are none.