db/sql_identifier.ts

SQL identifier validation for the places an identifier must be interpolated rather than parameterized.

PostgreSQL parameterizes values only — table and column names in DDL (DROP TABLE, TRUNCATE, ALTER) and the alias qualify_columns prefixes onto a projection (db/sql_columns.ts) have to be string-interpolated. This validator ensures such identifiers are safe to interpolate.

view source

Declarations
#

2 declarations

assert_valid_sql_identifier
#

db/sql_identifier.ts view source

(name: string): string import {assert_valid_sql_identifier} from '@fuzdev/fuz_app/db/sql_identifier.js';

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

  • Error - if the identifier contains characters outside `[a-zA-Z0-9_]` or starts with a digit

VALID_SQL_IDENTIFIER
#

db/sql_identifier.ts view source

RegExp import {VALID_SQL_IDENTIFIER} from '@fuzdev/fuz_app/db/sql_identifier.js';

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

Imported by
#