MCPcopy Create free account
hub / github.com/cloudflare/templates / isValidPostgresIdentifier

Function isValidPostgresIdentifier

postgres-hyperdrive-template/src/utils.ts:114–148  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

112 * @returns Result object indicating if the name is valid and an optional error message
113 */
114export function isValidPostgresIdentifier(name: string): {
115 valid: boolean;
116 message?: string;
117} {
118 if (!name || typeof name !== "string") {
119 return { valid: false, message: "Name is required" };
120 }
121
122 if (name.length > 63) {
123 return { valid: false, message: "Name exceeds 63 character limit" };
124 }
125
126 // Check if it starts with a digit
127 if (/^\d/.test(name)) {
128 return { valid: false, message: "Name cannot start with a number" };
129 }
130
131 // Check for valid characters
132 if (!/^[a-zA-Z0-9_]+$/.test(name)) {
133 return {
134 valid: false,
135 message: "Name can only contain letters, numbers, and underscores",
136 };
137 }
138
139 // Check against reserved keywords
140 if (POSTGRES_RESERVED_KEYWORDS.includes(name.toLowerCase())) {
141 return {
142 valid: false,
143 message: `"${name}" is a PostgreSQL reserved keyword`,
144 };
145 }
146
147 return { valid: true };
148}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected