db/sql_identifier.ts

SQL identifier validation for dynamic DDL queries.

PostgreSQL DDL operations (DROP TABLE, TRUNCATE, ALTER) do not support parameterized table/column names — only values can be parameterized. This validator ensures identifiers are safe for string interpolation in those specific cases.

Declarations
#

2 declarations

view source

assert_valid_sql_identifier
#

db/sql_identifier.ts view source

(name: string): string

Assert that a string is a valid SQL identifier.

Use this before interpolating table or column names into DDL queries where parameterized placeholders ($1) are not supported.

name

the identifier to validate

type string

returns

string

the validated identifier

throws

  • if - the identifier contains invalid characters

VALID_SQL_IDENTIFIER
#

db/sql_identifier.ts view source

RegExp

Pattern matching valid SQL identifiers: starts with a letter or underscore, followed by letters, digits, or underscores.

Imported by
#