Skip to content

Commit 754ced7

Browse files
committed
Enhance DocC output for ForeignKeyViolation
1 parent fb81ec6 commit 754ced7

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

GRDB/Core/Database+Schema.swift

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ public struct IndexInfo {
984984
/// ```
985985
///
986986
/// Related SQLite documentation: <https://www.sqlite.org/pragma.html#pragma_foreign_key_check>
987-
public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible {
987+
public struct ForeignKeyViolation {
988988
/// The name of the table that contains the foreign key.
989989
public var originTable: String
990990

@@ -1002,35 +1002,6 @@ public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible {
10021002
/// ``ForeignKeyInfo``. See ``Database/foreignKeys(on:)``.
10031003
public var foreignKeyId: Int
10041004

1005-
public init(row: Row) {
1006-
originTable = row[0]
1007-
originRowID = row[1]
1008-
destinationTable = row[2]
1009-
foreignKeyId = row[3]
1010-
}
1011-
1012-
/// A description of the foreign key violation.
1013-
///
1014-
/// For example:
1015-
///
1016-
/// ```
1017-
/// FOREIGN KEY constraint violation - from player to team, in rowid 1
1018-
/// ```
1019-
///
1020-
/// See also ``failureDescription(_:)``.
1021-
public var description: String {
1022-
if let originRowID = originRowID {
1023-
return """
1024-
FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \
1025-
in rowid \(originRowID)
1026-
"""
1027-
} else {
1028-
return """
1029-
FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable)
1030-
"""
1031-
}
1032-
}
1033-
10341005
/// A precise description of the foreign key violation.
10351006
///
10361007
/// For example:
@@ -1083,6 +1054,39 @@ public struct ForeignKeyViolation: FetchableRecord, CustomStringConvertible {
10831054
}
10841055
}
10851056

1057+
extension ForeignKeyViolation: FetchableRecord {
1058+
public init(row: Row) {
1059+
originTable = row[0]
1060+
originRowID = row[1]
1061+
destinationTable = row[2]
1062+
foreignKeyId = row[3]
1063+
}
1064+
}
1065+
1066+
extension ForeignKeyViolation: CustomStringConvertible {
1067+
/// A description of the foreign key violation.
1068+
///
1069+
/// For example:
1070+
///
1071+
/// ```
1072+
/// FOREIGN KEY constraint violation - from player to team, in rowid 1
1073+
/// ```
1074+
///
1075+
/// See also ``failureDescription(_:)``.
1076+
public var description: String {
1077+
if let originRowID = originRowID {
1078+
return """
1079+
FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \
1080+
in rowid \(originRowID)
1081+
"""
1082+
} else {
1083+
return """
1084+
FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable)
1085+
"""
1086+
}
1087+
}
1088+
}
1089+
10861090
/// Information about a primary key.
10871091
///
10881092
/// You get `PrimaryKeyInfo` instances with the ``Database/primaryKey(_:)``

0 commit comments

Comments
 (0)