Documentation
¶
Overview ¶
Package fingerprint provides SQL query normalization and fingerprinting.
Normalize replaces all literal values (strings, numbers, booleans, NULLs) with "?" placeholders and returns the re-formatted SQL. Two queries that are structurally identical but differ only in literal values will produce the same normalized output.
Fingerprint returns the SHA-256 hex digest of the normalized form, providing a stable 64-character key for query deduplication, caching, and slow-query grouping.
Existing parameter placeholders ($1, ?, :name) are always preserved unchanged.
Example:
n, err := fingerprint.Normalize("SELECT * FROM users WHERE id = 42")
// n == "SELECT * FROM users WHERE id = ?"
fp, err := fingerprint.Fingerprint("SELECT * FROM users WHERE id = 42")
// fp == "a3f1..." (64-char SHA-256 hex)
fp2, _ := fingerprint.Fingerprint("SELECT * FROM users WHERE id = 999")
// fp == fp2 (same structure, different literal)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fingerprint ¶
Fingerprint parses the SQL, normalizes all literals to "?", and returns the SHA-256 hex digest of the normalized form. Two structurally identical queries with different literal values will produce the same fingerprint.
The fingerprint is stable across GoSQLX versions as long as the formatter output for a given AST structure does not change.
Returns a 64-character lowercase hex string, or an error if SQL is invalid.
Example:
fp, err := fingerprint.Fingerprint("SELECT * FROM users WHERE id = 42")
fp2, _ := fingerprint.Fingerprint("SELECT * FROM users WHERE id = 999")
// fp == fp2 (same structure, different literal)
func Normalize ¶
Normalize parses the SQL, replaces all literal values (strings, numbers, booleans, NULLs) with "?" placeholders, and returns the re-formatted SQL.
Two queries that are structurally identical but use different literal values (e.g., WHERE id = 1 vs WHERE id = 42) will produce the same normalized output. Existing parameter placeholders ($1, ?, :name) are preserved unchanged.
Returns an error if the SQL cannot be parsed.
Example:
n, err := fingerprint.Normalize("SELECT * FROM users WHERE id = 42 AND name = 'alice'")
// n == "SELECT * FROM users WHERE id = ? AND name = ?"
Types ¶
This section is empty.