Crates.io | sql-redactor |
lib.rs | sql-redactor |
version | 0.1.0 |
source | src |
created_at | 2023-04-08 16:51:23.073147 |
updated_at | 2023-04-08 16:51:23.073147 |
description | A library to redact SQL queries for security and observability |
homepage | |
repository | |
max_upload_size | |
id | 833681 |
size | 10,500 |
Normalize and redact SQL queries. Supports many dialects such as mysql, postgres, clickhouse, or hive.
This is useful for adding the observability to your database.
It is hard to find the higest QPS query when the queries are parameterized:
SELECT * FROM users where user_id = 1000
with QPS 5SELECT * FROM users where user_id = 1001
with QPS 3SELECT * FROM users where user_id = 1002
with QPS 8SELECT * FROM articles where article_id = 2000
with QPS 2SELECT * FROM articles where article_id = 2001
with QPS 50SELECT * FROM articles where article_id = 2002
with QPS 3The parameters can be obscured to provide a better insight:
SELECT * FROM users where user_id = ?
with QPS 3,000SELECT * FROM articles where article_id = ?
with QPS 2,000cargo add sql-redactor
use sql_redactor::redact;
use sql_redactor::dialect::MySqlDialect;
let sql = "SELECT * FROM users
WHERE age > 18
AND city = 'New York'
ORDER BY last_name ASC;";
let redacted = "SELECT * FROM users WHERE age > ? AND city = ? ORDER BY last_name ASC;";
assert_eq!(redact(&MySqlDialect {}, sql).unwrap(), redacted);
The redaction is fast compared to typical db latencies.
AMD Ryzen 9 3900X
30us
SELECT * FROM foo WHERE bar = 1
60~70 us
SELECT * FROM users
WHERE age > 18
AND city = 'New York'
ORDER BY last_name ASC;