From 354d22d70d60ee960e904cded2017e2be0848868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 14 Feb 2019 08:16:09 +0100 Subject: [PATCH] Update documentation for literal interpolation --- GRDB/Core/Database+Statements.swift | 4 ++-- GRDB/Core/DatabaseValueConvertible.swift | 20 +++++++++---------- GRDB/Core/Row.swift | 6 +++--- GRDB/Core/SQLRequest.swift | 4 ++-- GRDB/Core/StatementColumnConvertible.swift | 20 +++++++++---------- .../QueryInterfaceRequest.swift | 8 ++++---- GRDB/QueryInterface/RequestProtocols.swift | 4 ++-- .../SQLExpression+QueryInterface.swift | 2 +- GRDB/Record/FetchableRecord.swift | 6 +++--- .../Contents.swift | 4 ++-- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index 0ca956f91..4d3fc6d87 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -145,11 +145,11 @@ extension Database { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// try db.execute(literal: SQLLiteral(""" + /// try db.execute(literal: """ /// INSERT INTO player (name) VALUES (\("Arthur")); /// INSERT INTO player (name) VALUES (\("Barbara")); /// INSERT INTO player (name) VALUES (\("O'Brien")); - /// """)) + /// """) /// /// This method may throw a DatabaseError. /// diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 1aee1d82f..28e406ea6 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -315,10 +315,10 @@ extension DatabaseValueConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(""" + /// let firstNames = try String.fetchCursor(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // Cursor of String + /// """) // Cursor of String /// /// If the database is modified during the cursor iteration, the remaining /// elements are undefined. @@ -348,10 +348,10 @@ extension DatabaseValueConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try String.fetchAll(db, literal: SQLLiteral(""" + /// let firstNames = try String.fetchAll(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // [String] + /// """) // [String] /// /// - parameters: /// - db: A database connection. @@ -376,10 +376,10 @@ extension DatabaseValueConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstName = try String.fetchOne(db, literal: SQLLiteral(""" + /// let firstName = try String.fetchOne(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // String? + /// """) // String? /// /// - parameters: /// - db: A database connection. @@ -621,10 +621,10 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try Optional.fetchCursor(db, literal: SQLLiteral(""" + /// let firstNames = try Optional.fetchCursor(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // Cursor of String? + /// """) // Cursor of String? /// /// If the database is modified during the cursor iteration, the remaining /// elements are undefined. @@ -654,10 +654,10 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try Optional.fetchAll(db, literal: SQLLiteral(""" + /// let firstNames = try Optional.fetchAll(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // [String?] + /// """) // [String?] /// /// - parameters: /// - db: A database connection. diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 3fa3f658f..626100d68 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -812,7 +812,7 @@ extension Row { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let rows = try Row.fetchCursor(db, literal: SQLLiteral(""" + /// let rows = try Row.fetchCursor(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // RowCursor /// @@ -853,7 +853,7 @@ extension Row { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let rows = try Row.fetchAll(db, literal: SQLLiteral(""" + /// let rows = try Row.fetchAll(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // [Row] /// @@ -881,7 +881,7 @@ extension Row { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let row = try Row.fetchOne(db, literal: SQLLiteral(""" + /// let row = try Row.fetchOne(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // Row? /// diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift index e5056636b..838fc52bb 100644 --- a/GRDB/Core/SQLRequest.swift +++ b/GRDB/Core/SQLRequest.swift @@ -43,9 +43,9 @@ public struct SQLRequest : FetchRequest { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let request = SQLRequest(literal: SQLLiteral(""" + /// let request = SQLRequest(literal: """ /// SELECT * FROM player WHERE name = \("O'brien") - /// """)) + /// """) /// /// - parameters: /// - sqlLiteral: An SQLLiteral. diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index ca49739a0..6a13687c2 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -300,10 +300,10 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(""" + /// let firstNames = try String.fetchCursor(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // Cursor of String + /// """) // Cursor of String /// /// If the database is modified during the cursor iteration, the remaining /// elements are undefined. @@ -333,10 +333,10 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try String.fetchAll(db, literal: SQLLiteral(""" + /// let firstNames = try String.fetchAll(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // [String] + /// """) // [String] /// /// - parameters: /// - db: A database connection. @@ -361,10 +361,10 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstName = try String.fetchOne(db, literal: SQLLiteral(""" + /// let firstName = try String.fetchOne(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // String? + /// """) // String? /// /// - parameters: /// - db: A database connection. @@ -602,10 +602,10 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try Optional.fetchCursor(db, literal: SQLLiteral(""" + /// let firstNames = try Optional.fetchCursor(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // Cursor of String? + /// """) // Cursor of String? /// /// If the database is modified during the cursor iteration, the remaining /// elements are undefined. @@ -635,10 +635,10 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let firstNames = try Optional.fetchAll(db, literal: SQLLiteral(""" + /// let firstNames = try Optional.fetchAll(db, literal: """ /// SELECT firstName FROM player /// WHERE lastName = \("O'Brien") - /// """)) // [String?] + /// """) // [String?] /// /// - parameters: /// - db: A database connection. diff --git a/GRDB/QueryInterface/QueryInterfaceRequest.swift b/GRDB/QueryInterface/QueryInterfaceRequest.swift index 464f7075e..b64826ecc 100644 --- a/GRDB/QueryInterface/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/QueryInterfaceRequest.swift @@ -133,7 +133,7 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest { /// let request = Player. /// .filter(primaryKey: 42) /// .select( - /// SQLLiteral("IFNULL(name, \("Anonymous"))"), + /// literal: "IFNULL(name, \("Anonymous"))", /// as: String.self) /// let name: String? = try request.fetchOne(db) /// } @@ -378,7 +378,7 @@ extension TableRecord { /// Creates a request which selects *sql*. /// /// // SELECT id, email FROM player - /// let request = Player.select(literal: SQLLiteral("id, email")) + /// let request = Player.select(literal: SQLLiteral(sql: "id, email")) public static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest { return all().select(literal: sqlLiteral) } @@ -424,7 +424,7 @@ extension TableRecord { /// /// try dbQueue.read { db in /// // SELECT max(score) FROM player - /// let request = Player.select(literal: SQLLiteral("max(score)"), as: Int.self) + /// let request = Player.select(literal: SQLLiteral(sql: "max(score)"), as: Int.self) /// let maxScore: Int? = try request.fetchOne(db) /// } public static func select(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest { @@ -517,7 +517,7 @@ extension TableRecord { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let request = Player.filter(literal: SQLLiteral("email = \("arthur@example.com"))) + /// let request = Player.filter(literal: "email = \("arthur@example.com")) /// /// The selection defaults to all columns. This default can be changed for /// all requests by the `TableRecord.databaseSelection` property, or diff --git a/GRDB/QueryInterface/RequestProtocols.swift b/GRDB/QueryInterface/RequestProtocols.swift index 02372b368..0a8ed630f 100644 --- a/GRDB/QueryInterface/RequestProtocols.swift +++ b/GRDB/QueryInterface/RequestProtocols.swift @@ -70,7 +70,7 @@ extension SelectionRequest { /// // SELECT id, email, score + 1000 FROM player /// let bonus = 1000 /// var request = Player.all() - /// request = request.select(literal: SQLLiteral(""" + /// request = request.select(literal: """ /// id, email, score + \(bonus) /// """) /// @@ -139,7 +139,7 @@ extension FilteredRequest { /// /// // SELECT * FROM player WHERE email = 'arthur@example.com' /// var request = Player.all() - /// request = request.filter(literal: SQLLiteral(""" + /// request = request.filter(literal: """ /// email = \("arthur@example.com") /// """) public func filter(literal sqlLiteral: SQLLiteral) -> Self { diff --git a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift index 40c9ff1c7..f9a16ba5b 100644 --- a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift @@ -65,7 +65,7 @@ public struct SQLExpressionLiteral : SQLExpression { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// SQLExpressionLiteral(literal: SQLLiteral("\(1) + \(2)")) + /// SQLExpressionLiteral(literal: "\(1) + \(2)") public init(literal sqlLiteral: SQLLiteral) { self.sqlLiteral = sqlLiteral } diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index 3a57a7f4c..efc160772 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -270,7 +270,7 @@ extension FetchableRecord { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let players = try Player.fetchCursor(db, literal: SQLLiteral(""" + /// let players = try Player.fetchCursor(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // Cursor of Player /// @@ -301,7 +301,7 @@ extension FetchableRecord { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let players = try Player.fetchAll(db, literal: SQLLiteral(""" + /// let players = try Player.fetchAll(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // [Player] /// @@ -327,7 +327,7 @@ extension FetchableRecord { /// With Swift 5, you can safely embed raw values in your SQL queries, /// without any risk of syntax errors or SQL injection: /// - /// let player = try Player.fetchOne(db, literal: SQLLiteral(""" + /// let player = try Player.fetchOne(db, literal: """ /// SELECT * FROM player WHERE lastName = \("O'Brien") /// """) // Player? /// diff --git a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift index afe78c803..02290a687 100644 --- a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift +++ b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift @@ -365,9 +365,9 @@ try dbQueue.read { db in //: without any risk of syntax errors or SQL injection: //: //: try dbQueue.read { db in -//: try Base.fetchAll(db, literal: SQLLiteral(""" +//: try Base.fetchAll(db, literal: """ //: SELECT ... WHERE name = \("O'Brien") -//: """)) // [Base] +//: """) // [Base] //: } extension MyDatabaseDecoder { // MARK: - Fetch from SQLLiteral