(identifier: string)
| 81 | * It is an error to call this function with a string that contains the zero code point. |
| 82 | */ |
| 83 | export function quoteIdentifier(identifier: string) { |
| 84 | // According to https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS, |
| 85 | // any string may be used as an identifier, except those that contain the zero code point. |
| 86 | // |
| 87 | // In order to support special characters, quoted identifiers must be used. |
| 88 | // Within a quoted identifier, the literal double-quote character must be escaped |
| 89 | // by writing it twice. |
| 90 | // For example, the identifier foo" is represented as "foo""" (including the quotes). |
| 91 | |
| 92 | // Materialize never allows any identifiers to be used whose name contains the null byte, |
| 93 | // so this assert should never fire unless this function is called with arbitrary user input. |
| 94 | assert(identifier.search("\0") === -1); |
| 95 | |
| 96 | return `"${identifier.replace(/"/g, '""')}"`; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Given an array of sql expressions, builds a string of WHERE + AND clauses. |
no test coverage detected