From d13968b7535fad0fc5a3bb7682f7601a53e71803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 16 Feb 2019 20:35:34 +0100 Subject: [PATCH] Documentation --- GRDB/Core/SQLInterpolation.swift | 2 +- GRDB/Core/SQLRequest.swift | 39 +++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/GRDB/Core/SQLInterpolation.swift b/GRDB/Core/SQLInterpolation.swift index 9c755a4ea..49bc2b3b0 100644 --- a/GRDB/Core/SQLInterpolation.swift +++ b/GRDB/Core/SQLInterpolation.swift @@ -1,12 +1,12 @@ #if swift(>=5.0) /// :nodoc: public struct SQLInterpolation: StringInterpolationProtocol { + var context = SQLGenerationContext.literalGenerationContext(withArguments: true) var sql: String var arguments: StatementArguments { get { return context.arguments! } set { context.arguments = newValue } } - var context = SQLGenerationContext.literalGenerationContext(withArguments: true) public init(literalCapacity: Int, interpolationCount: Int) { sql = "" diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift index 3c21bf912..1657805f4 100644 --- a/GRDB/Core/SQLRequest.swift +++ b/GRDB/Core/SQLRequest.swift @@ -1,11 +1,36 @@ /// A FetchRequest built from raw SQL. public struct SQLRequest : FetchRequest { + /// There are two statement caches: one "public" for statements generated by + /// the user, and one "internal" for the statements generated by GRDB. Those + /// are separated so that GRDB has no opportunity to inadvertently modify + /// the arguments of user's cached statements. + enum Cache { + /// The public cache, for library user + case `public` + + /// The internal cache, for GRDB + case `internal` + } + public typealias RowDecoder = T - public var adapter: RowAdapter? + /// The raw SQL query + /// + /// let id = 42 + /// let request: SQLRequest = "SELECT * FROM player WHERE id = \(id)" + /// request.sql // "SELECT * FROM player WHERE id = ?" public var sql: String { return sqlLiteral.sql } + + /// The request argument + /// + /// let id = 42 + /// let request: SQLRequest = "SELECT * FROM player WHERE id = \(id)" + /// request.arguments // [42] public var arguments: StatementArguments { return sqlLiteral.arguments } + /// The request adapter + public var adapter: RowAdapter? + private var sqlLiteral: SQLLiteral private let cache: Cache? @@ -116,18 +141,6 @@ public struct SQLRequest : FetchRequest { try statement.setArgumentsWithValidation(sqlLiteral.arguments) return (statement, adapter) } - - /// There are two statement caches: one for statements generated by the - /// user, and one for the statements generated by GRDB. Those are separated - /// so that GRDB has no opportunity to inadvertently modify the arguments of - /// user's cached statements. - enum Cache { - /// The public cache, for library user - case `public` - - /// The internal cache, for grdb - case `internal` - } } #if swift(>=5.0)