describeEmitErrorfunctionfunction describeEmitError(e: EmitError): stringOne sentence for an emit error.
Quoting and placeholders (commons lang-sql 0007-sql-emit FR-001 to FR-005): what the lexical of a dialect already knows, as functions, so that a library that builds statements writes no quote and no parameter by hand. An identifier is quoted as the dialect's first quoted-identifier syntax writes it, a string as its first string syntax writes it, and a parameter in the style the dialect reads; each result is read back by the lexer of the same dialect as one token.
quoteIdent(postgres, 'a"b'); // ok('"a""b"')
identifier(postgres, "user"); // ok('"user"'): a keyword is quoted
quoteString(mysql, "it's"); // ok("'it\\'s'")
placeholder(postgres, 2); // ok("$2")
placeholder(sqlite, 1, "name"); // ok(":name")Spec: 0007-sql-emit FR-001, FR-002, FR-004
describeEmitErrorfunctionfunction describeEmitError(e: EmitError): stringOne sentence for an emit error.
EmitErrortypeno test imports ittype EmitError =
| { readonly kind: "no-quoted-identifier"; readonly dialect: string }
| { readonly kind: "no-string"; readonly dialect: string }
| { readonly kind: "cannot-escape"; readonly dialect: string; readonly quote: string }
| { readonly kind: "no-placeholder"; readonly dialect: string; readonly wanted: "named" | "positional" };Why a name, a value or a parameter could not be written for a dialect.
identifierfunctionfunction identifier(dialect: Dialect, name: string): Result<string, EmitError>The name bare where it is a plain lower-case word that is not a keyword of the dialect, and quoted otherwise.
paramStylesfunctionfunction paramStyles(dialect: Dialect): readonly ParamStyle[]The styles of parameter the dialect reads, in the order its lexical lists them.
placeholderfunctionfunction placeholder(dialect: Dialect, position: number, name?: string | undefined): Result<string, EmitError>The text of a parameter: for a name, the first of the colon, at and dollar styles the dialect has; for a position (from 1), $n or ?; an error value where none fits.
qualifiedfunctionfunction qualified(dialect: Dialect, parts: readonly string[]): Result<string, EmitError>The parts joined by ., each as identifier gives it.
quoteIdentfunctionfunction quoteIdent(dialect: Dialect, name: string): Result<string, EmitError>The name written as the dialect's first quoted-identifier syntax writes it; an error value where the dialect has none.
quoteStringfunctionfunction quoteString(dialect: Dialect, value: string): Result<string, EmitError>The value written as the dialect's first string syntax writes it; an error value where the dialect has none, or where the quote cannot be written inside.