From 19061934cea1cc8bd549a52333449dfcbe445214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 9 Mar 2020 08:49:06 +0100 Subject: [PATCH] SE-0242: Synthesize default values for the memberwise initializer ...and more initializers cleanup --- GRDB/Core/StatementAuthorizer.swift | 3 --- .../DatabaseValueConvertible+Decodable.swift | 7 ------ .../DatabaseValueConvertible+Encodable.swift | 4 ---- GRDB/Migration/Migration.swift | 6 ----- .../Association/AssociationAggregate.swift | 6 +---- .../Request/QueryInterfaceRequest.swift | 8 +++---- GRDB/QueryInterface/SQL/SQLQuery.swift | 22 +++---------------- GRDB/QueryInterface/SQL/SQLRelation.swift | 22 ++++--------------- GRDB/Record/EncodableRecord+Encodable.swift | 9 -------- 9 files changed, 11 insertions(+), 76 deletions(-) diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index 5028df40b..af253233f 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -193,9 +193,6 @@ final class TruncateOptimizationBlocker: StatementAuthorizer { private struct AuthorizerActionCode: RawRepresentable, CustomStringConvertible { let rawValue: Int32 - init(rawValue: Int32) { - self.rawValue = rawValue - } var description: String { switch rawValue { diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift index bdf087905..e9ed49e80 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift @@ -151,13 +151,6 @@ private struct DatabaseValueDecodingContainer: SingleValueDecodingContainer { private struct DatabaseValueDecoder: Decoder { let dbValue: DatabaseValue - - init(dbValue: DatabaseValue, codingPath: [CodingKey]) { - self.dbValue = dbValue - self.codingPath = codingPath - } - - // Decoder let codingPath: [CodingKey] var userInfo: [CodingUserInfoKey: Any] { [:] } diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift index d4496c4ef..42d73482c 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift @@ -55,10 +55,6 @@ private struct DatabaseValueEncoder: Encoder { /// Any contextual information set by the user for encoding. var userInfo: [CodingUserInfoKey: Any] = [:] - init(encode: @escaping (DatabaseValue) -> Void) { - self.encode = encode - } - /// Returns an encoding container appropriate for holding multiple values keyed by the given key type. /// /// - parameter type: The key type to use for the container. diff --git a/GRDB/Migration/Migration.swift b/GRDB/Migration/Migration.swift index 4efcb0590..3fc5e59c8 100644 --- a/GRDB/Migration/Migration.swift +++ b/GRDB/Migration/Migration.swift @@ -11,11 +11,6 @@ struct Migration { let identifier: String let migrate: (Database) throws -> Void - init(identifier: String, migrate: @escaping (Database) throws -> Void) { - self.identifier = identifier - self.migrate = migrate - } - func run(_ db: Database) throws { // PRAGMA foreign_key_check and SQLITE_CONSTRAINT_FOREIGNKEY were // introduced in SQLite 3.7.16 @@ -27,7 +22,6 @@ struct Migration { } } - private func runWithoutDisabledForeignKeys(_ db: Database) throws { try db.inTransaction(.immediate) { try migrate(db) diff --git a/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift b/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift index e31d01c73..5caf9dd73 100644 --- a/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift +++ b/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift @@ -63,11 +63,7 @@ public struct AssociationAggregate { let prepare: AssociationAggregatePreparation /// The SQL name for the value of this aggregate. See forKey(_:). - var key: String? - - init(_ prepare: @escaping AssociationAggregatePreparation) { - self.prepare = prepare - } + var key: String? = nil } extension AssociationAggregate: KeyPathRefining { diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index 8d0951811..6ccf7cad7 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -30,11 +30,9 @@ /// See https://github.com/groue/GRDB.swift#the-query-interface public struct QueryInterfaceRequest { var query: SQLQuery - - init(query: SQLQuery) { - self.query = query - } - +} + +extension QueryInterfaceRequest { init(relation: SQLRelation) { self.init(query: SQLQuery(relation: relation)) } diff --git a/GRDB/QueryInterface/SQL/SQLQuery.swift b/GRDB/QueryInterface/SQL/SQLQuery.swift index 12bb95cbe..80890e010 100644 --- a/GRDB/QueryInterface/SQL/SQLQuery.swift +++ b/GRDB/QueryInterface/SQL/SQLQuery.swift @@ -3,30 +3,14 @@ /// See SQLQueryGenerator for actual SQL generation. struct SQLQuery { var relation: SQLRelation - var isDistinct: Bool - var expectsSingleResult: Bool + var isDistinct: Bool = false + var expectsSingleResult: Bool = false var groupPromise: DatabasePromise<[SQLExpression]>? // Having clause is an array of expressions that we'll join with // the AND operator. This gives nicer output in generated SQL: // `(a AND b AND c)` instead of `((a AND b) AND c)`. - var havingExpressions: [SQLExpression] + var havingExpressions: [SQLExpression] = [] var limit: SQLLimit? - - init( - relation: SQLRelation, - isDistinct: Bool = false, - expectsSingleResult: Bool = false, - groupPromise: DatabasePromise<[SQLExpression]>? = nil, - havingExpressions: [SQLExpression] = [], - limit: SQLLimit? = nil) - { - self.relation = relation - self.isDistinct = isDistinct - self.expectsSingleResult = expectsSingleResult - self.groupPromise = groupPromise - self.havingExpressions = havingExpressions - self.limit = limit - } } extension SQLQuery: KeyPathRefining { diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index e28d67e3d..3ef8e3b1d 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -149,13 +149,13 @@ struct SQLRelation { } var source: SQLSource - var selection: [SQLSelectable] + var selection: [SQLSelectable] = [] // Filter is an array of expressions that we'll join with the AND operator. // This gives nicer output in generated SQL: `(a AND b AND c)` instead of // `((a AND b) AND c)`. - var filtersPromise: DatabasePromise<[SQLExpression]> - var ordering: SQLRelation.Ordering - var children: OrderedDictionary + var filtersPromise: DatabasePromise<[SQLExpression]> = DatabasePromise(value: []) + var ordering: SQLRelation.Ordering = SQLRelation.Ordering() + var children: OrderedDictionary = [:] var prefetchedAssociations: [SQLAssociation] { children.flatMap { key, child -> [SQLAssociation] in @@ -175,20 +175,6 @@ struct SQLRelation { } } } - - init( - source: SQLSource, - selection: [SQLSelectable] = [], - filtersPromise: DatabasePromise<[SQLExpression]> = DatabasePromise(value: []), - ordering: SQLRelation.Ordering = SQLRelation.Ordering(), - children: OrderedDictionary = [:]) - { - self.source = source - self.selection = selection - self.filtersPromise = filtersPromise - self.ordering = ordering - self.children = children - } } extension SQLRelation: KeyPathRefining { diff --git a/GRDB/Record/EncodableRecord+Encodable.swift b/GRDB/Record/EncodableRecord+Encodable.swift index 01adf4983..2708def6b 100644 --- a/GRDB/Record/EncodableRecord+Encodable.swift +++ b/GRDB/Record/EncodableRecord+Encodable.swift @@ -48,11 +48,6 @@ private class RecordEncoder: Encoder { private struct KeyedContainer: KeyedEncodingContainerProtocol { var recordEncoder: RecordEncoder var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo } - - init(recordEncoder: RecordEncoder) { - self.recordEncoder = recordEncoder - } - var codingPath: [CodingKey] { [] } // swiftlint:disable comma @@ -236,10 +231,6 @@ private struct JSONRequiredEncoder: Encoder { var codingPath: [CodingKey] var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo } - init(codingPath: [CodingKey]) { - self.codingPath = codingPath - } - func container(keyedBy type: Key.Type) -> KeyedEncodingContainer where Key: CodingKey { let container = KeyedContainer(codingPath: codingPath) return KeyedEncodingContainer(container)