From 4c88d792f098a8b95df4532ccd3c2dd63e7916fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 14 Mar 2021 14:13:29 +0100 Subject: [PATCH] Documentation --- GRDB/Core/SQLInterpolation.swift | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/GRDB/Core/SQLInterpolation.swift b/GRDB/Core/SQLInterpolation.swift index 8f45697b6..464d25593 100644 --- a/GRDB/Core/SQLInterpolation.swift +++ b/GRDB/Core/SQLInterpolation.swift @@ -7,28 +7,45 @@ public struct SQLInterpolation: StringInterpolationProtocol { elements.reserveCapacity(interpolationCount + 1) } - /// "SELECT * FROM player" public mutating func appendLiteral(_ sql: String) { if sql.isEmpty { return } elements.append(.sql(sql)) } - /// "SELECT * FROM \(sql: "player")" + /// Appends a raw SQL snippet, with eventual arguments. + /// + /// For example: + /// + /// "SELECT * FROM \(sql: "player")" + /// "SELECT * FROM player WHERE \(sql: "name = ?", arguments: ["O'Brien"])" public mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) { elements.append(.sql(sql, arguments)) } - /// "SELECT * FROM player WHERE \(SQLLiteral(...))" + /// Appends a raw SQL literal. + /// + /// For example: + /// + /// "SELECT * FROM \(SQLLiteral("player"))" + /// "SELECT * FROM player WHERE \(SQLLiteral("name = \("O'Brien")"))" public mutating func appendInterpolation(_ sqlLiteral: SQLLiteral) { elements.append(contentsOf: sqlLiteral.elements) } - - /// "SELECT * FROM player WHERE \(SQLLiteral(...))" + + /// Appends a String expression. + /// + /// For example: + /// + /// "SELECT * FROM player WHERE name = \("O'Brien")" public mutating func appendInterpolation(_ string: S) { elements.append(.expression(String(string).sqlExpression)) } - - /// "SELECT * FROM player WHERE \(literal: "...")" + + /// Appends a raw SQL literal. + /// + /// For example: + /// + /// "SELECT * FROM player WHERE \(literal: "name = \("O'Brien")")" public mutating func appendInterpolation(literal sqlLiteral: SQLLiteral) { elements.append(contentsOf: sqlLiteral.elements) }