module CQL::Performance::SQLUtils

Overview

SQL normalization and formatting

Defined in:

performance/utilities.cr

Constant Summary

NORMALIZABLE_TOKEN = /\$\d+|\b\d+\b|'.+?'|\s+/

One pass over the original four rewrites (placeholders, bare numbers, quoted literals, whitespace runs). Each alternative starts with a distinct character class, so leftmost matching reproduces the sequential output exactly. \$\d+ must stay before \b\d+\b so the digits of a $1 placeholder are not matched as a bare number. A literal ? is already its own replacement and needs no alternative.

NORMALIZED_CACHE_LIMIT = 512

Class Method Summary

Class Method Detail

def self.format_params(params : Array(DB::Any), max_length : Int32 = 50) : String #

[View source]
def self.normalize_sql(sql : String) : String #

Queries repeat the same SQL text (values are bound), so each text is normalized once; at most NORMALIZED_CACHE_LIMIT are kept, the oldest inserted dropped first.


[View source]
def self.normalized_cache_size : Int32 #

[View source]
def self.truncate_sql(sql : String, max_length : Int32 = 100) : String #

[View source]