Documentation

This commit is contained in:
Gwendal Roué committed 2021-03-14 14:13:29 +01:00
1 parent 9d64a32814
commit 4c88d792f0
1 file changed
+24 -7
+24 -7
View File
@@ -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<S: StringProtocol>(_ 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)
}