Skip to content

Add additional interpolations, constructors, and operations to SQLQueryString

Compare
Choose a tag to compare
@tanner0101 tanner0101 released this 22 Jun 20:23
d044d36
This patch was authored and released by @gwynne.

Several new capabilities are available on SQLQueryString, as used by SQLRawBuilder:

  • Integer literal interpolation, e.g. \(literal: 1), for rendering correctly escaped numeric literals according to the database's SQLDialect
  • Boolean literal interpolation, e.g. \(literal: true), for rendering correctly escaped boolean literals according to the database's SQLDialect
  • String literal interpolation, e.g. \(literal: "hello"), for rendering strings as correctly escaped literal values in the database's SQLDialect
  • Arrays of string literals interpolation, e.g. \(literals: ["hello", "world", "how", "are", "you"], joinedBy: " ")
  • SQL identifier interpolation, e.g. \(ident: "created_at"), for rendering names as correctly escaped identifiers according to the database's SQLDialect - identifiers are usually table names, column names, alias names for tables and columns, and other similar items. PostgreSQL and SQLite enclose identifiers in " characters; MySQL uses backticks.
  • Arrays of SQL identifiers interpolation, e.g. \(idents: ["id", "created_at", "updated_at"], joinedBy: ", ") - great for generating column name lists for INSERT, for example.
  • A + operator for concatenating two SQLQueryStrings. Credit for this functionality goes to @t-ae in #111.
  • Array<SQLQueryString>.joined(separator:), similar to Array<String>.joined(separator:). Credit for this functionality goes to @t-ae in #111.
  • Improved tests for SQLQueryString. Partial credit for the improvements goes to @t-ae in #111.