From 754ced7b5e28b70defe5634546e237dae50c8005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 7 Nov 2022 22:50:50 +0100 Subject: [PATCH] Enhance DocC output for ForeignKeyViolation --- GRDB/Core/Database+Schema.swift | 64 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index dbe19bf0c..45694761f 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -984,7 +984,7 @@ public struct IndexInfo { /// ``` /// /// Related SQLite documentation: -public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible { +public struct ForeignKeyViolation { /// The name of the table that contains the foreign key. public var originTable: String @@ -1002,35 +1002,6 @@ public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible { /// ``ForeignKeyInfo``. See ``Database/foreignKeys(on:)``. public var foreignKeyId: Int - public init(row: Row) { - originTable = row[0] - originRowID = row[1] - destinationTable = row[2] - foreignKeyId = row[3] - } - - /// A description of the foreign key violation. - /// - /// For example: - /// - /// ``` - /// FOREIGN KEY constraint violation - from player to team, in rowid 1 - /// ``` - /// - /// See also ``failureDescription(_:)``. - public var description: String { - if let originRowID = originRowID { - return """ - FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \ - in rowid \(originRowID) - """ - } else { - return """ - FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable) - """ - } - } - /// A precise description of the foreign key violation. /// /// For example: @@ -1083,6 +1054,39 @@ public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible { } } +extension ForeignKeyViolation: FetchableRecord { + public init(row: Row) { + originTable = row[0] + originRowID = row[1] + destinationTable = row[2] + foreignKeyId = row[3] + } +} + +extension ForeignKeyViolation: CustomStringConvertible { + /// A description of the foreign key violation. + /// + /// For example: + /// + /// ``` + /// FOREIGN KEY constraint violation - from player to team, in rowid 1 + /// ``` + /// + /// See also ``failureDescription(_:)``. + public var description: String { + if let originRowID = originRowID { + return """ + FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \ + in rowid \(originRowID) + """ + } else { + return """ + FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable) + """ + } + } +} + /// Information about a primary key. /// /// You get `PrimaryKeyInfo` instances with the ``Database/primaryKey(_:)``