Documentation ¶
Index ¶
Constants ¶
const ( ArrayPlaceholder = "( ? )" BracketPlaceholder = "[ ? ]" )
const ( StringPlaceholder = "?" NumberPlaceholder = "?" )
const ( // DBMSSQLServer is a MS SQL Server DBMSSQLServer = "mssql" // DBMSPostgres is a PostgreSQL Server DBMSPostgres = "postgresql" // DBMSMySQL is a MySQL Server DBMSMySQL = "mysql" // DBMSOracle is a Oracle Server DBMSOracle = "oracle" )
Variables ¶
Functions ¶
func DiscardSQLAlias ¶
DiscardSQLAlias removes any SQL alias from the input string and returns the modified string. It uses a regular expression to match the alias pattern and replace it with an empty string. The function is case-insensitive and matches the pattern "AS <alias_name>". The input string is not modified in place.
Types ¶
type NormalizedInfo ¶
type SQLLexer ¶
type SQLLexer struct {
// contains filtered or unexported fields
}
SQL Lexer inspired from Rob Pike's talk on Lexical Scanning in Go
func NewSQLLexer ¶
func (*SQLLexer) ScanAllTokens ¶
ScanAllTokens scans the entire input string and returns a channel of tokens. Use this if you want to process the tokens as they are scanned.
type SQLNormalizer ¶
type SQLNormalizer struct {
// contains filtered or unexported fields
}
func NewSQLNormalizer ¶
func NewSQLNormalizer(config *SQLNormalizerConfig) *SQLNormalizer
func (*SQLNormalizer) Normalize ¶
func (n *SQLNormalizer) Normalize(input string) (string, *NormalizedInfo, error)
Normalize takes an input SQL string and returns a normalized SQL string, a NormalizedInfo struct, and an error. The normalizer collapses input SQL into compact format, groups obfuscated values into single placeholder, and collects metadata such as table names, comments, and commands.
type SQLNormalizerConfig ¶
type SQLNormalizerConfig struct { DBMS string `json:"dbms"` // CollectTables specifies whether the normalizer should also extract the table names that a query addresses CollectTables bool `json:"collect_tables"` // CollectCommands specifies whether the normalizer should extract and return commands as SQL metadata CollectCommands bool `json:"collect_commands"` // CollectComments specifies whether the normalizer should extract and return comments as SQL metadata CollectComments bool `json:"collect_comments"` // KeepSQLAlias reports whether SQL aliases ("AS") should be truncated. KeepSQLAlias bool `json:"keep_sql_alias"` }
type SQLObfuscator ¶
type SQLObfuscator struct {
// contains filtered or unexported fields
}
func NewSQLObfuscator ¶
func NewSQLObfuscator(config *SQLObfuscatorConfig) *SQLObfuscator
func (*SQLObfuscator) Obfuscate ¶
func (o *SQLObfuscator) Obfuscate(input string) string
Obfuscate takes an input SQL string and returns an obfuscated SQL string. The obfuscator replaces all literal values with a single placeholder
type SQLObfuscatorConfig ¶
type TokenType ¶
type TokenType int
const ( ERROR TokenType = iota EOF WS // whitespace STRING // string literal INCOMPLETE_STRING // illegal string literal so that we can obfuscate it, e.g. 'abc NUMBER // number literal IDENT // identifier OPERATOR // operator WILDCARD // wildcard * COMMENT // comment MULTILINE_COMMENT // multiline comment PUNCTUATION // punctuation DOLLAR_QUOTED_FUNCTION // dollar quoted function DOLLAR_QUOTED_STRING // dollar quoted string NUMBERED_PARAMETER // numbered parameter UNKNOWN // unknown token )