Documentation
¶
Overview ¶
Package sqlident validates and quotes SQL identifiers.
Values in Hermod's generated SQL are parameterized, but *identifiers* — table and schema names — cannot be: no driver supports a placeholder in `INSERT INTO ?`. They are interpolated into the statement, so they have to be proven safe before they get there.
That mattered more than it looks. A SQL sink without an explicit table name falls back to the table and schema carried on the message itself, and a message's table can come from the wire: the WebSocket source sets it straight from the inbound envelope (`m.SetTable(env.Table)`). A peer could therefore choose the identifier that gets pasted into a MERGE or INSERT against the destination database — arbitrary SQL execution on a system that is usually far more sensitive than Hermod itself. The same held, with an authenticated Editor rather than a remote peer, for identifiers taken from sink config.
Validation is deliberately strict rather than clever. It allows what a table name legitimately is and rejects everything else, instead of trying to escape hostile input — an allowlist cannot be outwitted by a quoting trick.
Index ¶
Constants ¶
const MaxLength = 128
MaxLength bounds an identifier. The shortest limit among the databases Hermod targets is 63 bytes (PostgreSQL); 128 covers the rest with room to spare, and any name longer than that is not a real table.
Variables ¶
This section is empty.
Functions ¶
func MustBeSafe ¶
MustBeSafe returns name unchanged when it validates, and an error otherwise. It is the minimal call site for code that already builds its own SQL and just needs the identifier checked before interpolation.
func Quote ¶
Quote validates name and returns it quoted for the dialect.
Quoting alone is not the defence — validation is. Quoting on top means a legitimate name that collides with a reserved word still works.
func Validate ¶
Validate reports whether name is a safe SQL identifier, optionally schema-qualified as `schema.table`.
Accepted: an optional schema part and a name part, each starting with a letter or underscore and continuing with letters, digits or underscores. Everything else — quotes, semicolons, whitespace, comment markers, unicode look-alikes, empty parts — is rejected.