Crate sql_fingerprint

Source
Expand description

§sql-fingerprint

Documentation Changelog CI Crates.io pre-commit

A SQL fingerprinter.

sql-fingerprint reduces SQL queries to recognizable fingerprints for easier comparison. The goal is to provide readable traces from queries captured during tests, so that changes can be tracked over time.

For example, given a query like:

SELECT name, age /* computed */ FROM cheeses WHERE origin = 'France'

…it will output a fingerprint like:

SELECT ... FROM cheeses WHERE ...

The fingerprinting process applies these changes:

  • Comments are dropped.
  • Whitespace is normalized to a single space.
  • Identifier and value lists are reduced to ‘…’.
  • Identifiers consisting of letters, numbers, and underscores have any quoting removed.
  • Savepoint IDs are replaced with ‘s1’, ‘s2’, etc.
  • Unparsable SQL is returned unchanged.

Functions§

fingerprint_many
Fingerprint multiple SQL strings. Doing so for a batch of strings allows sharing some state, such as savepoint ID aliases.
fingerprint_one
Fingerprint a single SQL string.