From cdc102de70407db56ec7245214d98e02b87d0e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 28 Feb 2016 22:14:49 +0100 Subject: [PATCH] Remove DatabaseRawRepresentable since DatabaseValueConvertible is enough. --- CHANGELOG.md | 2 +- GRDB.xcodeproj/project.pbxproj | 24 +++++++++---------- ...esentable.swift => RawRepresentable.swift} | 12 ++++------ README.md | 8 +++---- ...ests.swift => RawRepresentableTests.swift} | 8 +++---- 5 files changed, 26 insertions(+), 28 deletions(-) rename GRDB/Core/Support/StandardLibrary/{DatabaseRawRepresentable.swift => RawRepresentable.swift} (64%) rename Tests/Public/Core/DatabaseValueConvertible/{DatabaseRawRepresentableTests.swift => RawRepresentableTests.swift} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3cf1e7c..93a126adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Release Notes **Breaking Changes** -- `DatabaseIntRepresentable`, `DatabaseInt32Representable`, `DatabaseInt64Representable` and `DatabaseStringRepresentable` have been replaced by the single protocol `DatabaseRawRepresentable` ([documentation](https://github.com/groue/GRDB.swift#swift-enums)) +- `DatabaseIntRepresentable`, `DatabaseInt32Representable`, `DatabaseInt64Representable` and `DatabaseStringRepresentable` have been replaced by the single protocol `DatabaseValueConvertible` ([documentation](https://github.com/groue/GRDB.swift#swift-enums)) ## 0.45.1 diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 7841df2cf..8d54dd920 100644 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -31,8 +31,8 @@ 5605F16E1C672E4000235C62 /* Row+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1541C672E4000235C62 /* Row+Foundation.swift */; }; 5605F16F1C672E4000235C62 /* StatementArguments+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1551C672E4000235C62 /* StatementArguments+Foundation.swift */; }; 5605F1701C672E4000235C62 /* StatementArguments+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1551C672E4000235C62 /* StatementArguments+Foundation.swift */; }; - 5605F1711C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */; }; - 5605F1721C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */; }; + 5605F1711C672E4000235C62 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* RawRepresentable.swift */; }; + 5605F1721C672E4000235C62 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* RawRepresentable.swift */; }; 5605F1731C672E4000235C62 /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; 5605F1741C672E4000235C62 /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; 5605F1871C69111300235C62 /* SelectStatementSourceTablesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* SelectStatementSourceTablesTests.swift */; }; @@ -114,8 +114,8 @@ 56A2383F1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; 56A238401B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; 56A238421B9C74A90082EB20 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; }; - 56A238431B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */; }; - 56A238441B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */; }; + 56A238431B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; }; + 56A238441B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; }; 56A238451B9C74A90082EB20 /* DictionaryRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* DictionaryRowTests.swift */; }; 56A238461B9C74A90082EB20 /* DictionaryRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* DictionaryRowTests.swift */; }; 56A238471B9C74A90082EB20 /* DetachedRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */; }; @@ -313,7 +313,7 @@ 5605F1531C672E4000235C62 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURL.swift; sourceTree = ""; }; 5605F1541C672E4000235C62 /* Row+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+Foundation.swift"; sourceTree = ""; }; 5605F1551C672E4000235C62 /* StatementArguments+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+Foundation.swift"; sourceTree = ""; }; - 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRawRepresentable.swift; sourceTree = ""; }; + 5605F1571C672E4000235C62 /* RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = ""; }; 5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = ""; }; 5605F1861C69111300235C62 /* SelectStatementSourceTablesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementSourceTablesTests.swift; sourceTree = ""; }; 5605F1891C6B1A8700235C62 /* SQLCollation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollation.swift; sourceTree = ""; }; @@ -350,7 +350,7 @@ 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = ""; }; 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleSubclassTests.swift; sourceTree = ""; }; 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionTests.swift; sourceTree = ""; }; - 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRawRepresentableTests.swift; sourceTree = ""; }; + 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; 56A2381E1B9C74A90082EB20 /* DictionaryRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryRowTests.swift; sourceTree = ""; }; 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetachedRowTests.swift; sourceTree = ""; }; 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementTests.swift; sourceTree = ""; }; @@ -537,7 +537,7 @@ 5605F1561C672E4000235C62 /* StandardLibrary */ = { isa = PBXGroup; children = ( - 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */, + 5605F1571C672E4000235C62 /* RawRepresentable.swift */, 5605F1581C672E4000235C62 /* StandardLibrary.swift */, ); path = StandardLibrary; @@ -680,7 +680,7 @@ 56A238191B9C74A90082EB20 /* DatabaseValueConvertible */ = { isa = PBXGroup; children = ( - 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */, + 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */, 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */, 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */, 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */, @@ -1282,7 +1282,7 @@ 5605F15A1C672E4000235C62 /* CGFloat.swift in Sources */, 5605F1641C672E4000235C62 /* NSDate.swift in Sources */, 5605F1901C6B1A8700235C62 /* SQLFunction.swift in Sources */, - 5605F1721C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */, + 5605F1721C672E4000235C62 /* RawRepresentable.swift in Sources */, 563445061C4A7FD7003D3DC6 /* Utils.swift in Sources */, 56A238941B9C750B0082EB20 /* DatabaseMigrator.swift in Sources */, 5605F16A1C672E4000235C62 /* NSString.swift in Sources */, @@ -1346,7 +1346,7 @@ 56A238421B9C74A90082EB20 /* DatabaseValueConversionTests.swift in Sources */, 5658420F1C1A1C820099FE88 /* MutablePersistableTests.swift in Sources */, 56FC78671BBAEB8C00CA1285 /* MappingTests.swift in Sources */, - 56A238441B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */, + 56A238441B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */, 5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */, 565D5D721BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */, 56A2386A1B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */, @@ -1405,7 +1405,7 @@ 56A238671B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */, 56300B611C53C42C005A543B /* RowConvertible+FetchRequestTests.swift in Sources */, 56A2385D1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */, - 56A238431B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */, + 56A238431B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */, 56EB0AB21BCD787300A3DC55 /* NSDataMemoryTests.swift in Sources */, 56FC78681BBAEB8C00CA1285 /* ManagedDataControllerTests.swift in Sources */, 5658420E1C1A1C820099FE88 /* MutablePersistableTests.swift in Sources */, @@ -1452,7 +1452,7 @@ 5605F1591C672E4000235C62 /* CGFloat.swift in Sources */, 5605F1631C672E4000235C62 /* NSDate.swift in Sources */, 5605F18F1C6B1A8700235C62 /* SQLFunction.swift in Sources */, - 5605F1711C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */, + 5605F1711C672E4000235C62 /* RawRepresentable.swift in Sources */, 56A2387B1B9C75030082EB20 /* Configuration.swift in Sources */, 5605F1691C672E4000235C62 /* NSString.swift in Sources */, 5605F16D1C672E4000235C62 /* Row+Foundation.swift in Sources */, diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseRawRepresentable.swift b/GRDB/Core/Support/StandardLibrary/RawRepresentable.swift similarity index 64% rename from GRDB/Core/Support/StandardLibrary/DatabaseRawRepresentable.swift rename to GRDB/Core/Support/StandardLibrary/RawRepresentable.swift index e170e7bc0..5aed73218 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseRawRepresentable.swift +++ b/GRDB/Core/Support/StandardLibrary/RawRepresentable.swift @@ -1,5 +1,5 @@ -/// Have your RawRepresentable type adopt DatabaseRawRepresentable and it -/// automatically gains DatabaseValueConvertible adoption. +/// DatabaseValueConvertible is free for RawRepresentable types whose raw value +/// is itself DatabaseValueConvertible: /// /// enum Color : Int { /// case Red @@ -7,15 +7,13 @@ /// case Rose /// } /// -/// // Declare DatabaseRawRepresentable adoption: -/// extension Color : DatabaseRawRepresentable { } +/// // Declare DatabaseValueConvertible adoption: +/// extension Color : DatabaseValueConvertible { } /// /// // Gain full GRDB.swift support: /// db.execute("INSERT INTO colors (color) VALUES (?)", [Color.Red]) /// let color: Color? = Color.fetchOne(db, "SELECT ...") -public protocol DatabaseRawRepresentable: RawRepresentable, DatabaseValueConvertible { } - -public extension DatabaseRawRepresentable where RawValue: DatabaseValueConvertible { +public extension RawRepresentable where Self: DatabaseValueConvertible, Self.RawValue: DatabaseValueConvertible { /// Returns a value that can be stored in the database. var databaseValue: DatabaseValue { diff --git a/README.md b/README.md index af9d2cbea..f96eaed75 100644 --- a/README.md +++ b/README.md @@ -814,7 +814,7 @@ let amount = NSDecimalNumber(longLong: integerAmount) ### Swift Enums -**Swift enums** get full support from GRDB as long as their raw values are Int, Int32, Int64 or String: +**Swift enums** get full support from GRDB as long as their raw values are supported (Int, Int32, Int64 or String): ```swift enum Color : Int { @@ -826,11 +826,11 @@ enum Grape : String { } ``` -Add conformance to the `DatabaseRawRepresentable` protocol, and the enum type can be stored and fetched from the database just like other [value types](#values): +Add conformance to the `DatabaseValueConvertible` protocol, and the enum type can be stored and fetched from the database just like other [value types](#values): ```swift -extension Color : DatabaseRawRepresentable { } -extension Grape : DatabaseRawRepresentable { } +extension Color : DatabaseValueConvertible { } +extension Grape : DatabaseValueConvertible { } // Store try db.execute("INSERT INTO wines (grape, color) VALUES (?, ?)", diff --git a/Tests/Public/Core/DatabaseValueConvertible/DatabaseRawRepresentableTests.swift b/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift similarity index 97% rename from Tests/Public/Core/DatabaseValueConvertible/DatabaseRawRepresentableTests.swift rename to Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift index ca18bb7b2..53ff25538 100644 --- a/Tests/Public/Core/DatabaseValueConvertible/DatabaseRawRepresentableTests.swift +++ b/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift @@ -25,10 +25,10 @@ enum Grape : String { case Riesling } -extension Color32 : DatabaseRawRepresentable { } -extension Color64 : DatabaseRawRepresentable { } -extension Color : DatabaseRawRepresentable { } -extension Grape : DatabaseRawRepresentable { } +extension Color32 : DatabaseValueConvertible { } +extension Color64 : DatabaseValueConvertible { } +extension Color : DatabaseValueConvertible { } +extension Grape : DatabaseValueConvertible { } class RawRepresentableTests: GRDBTestCase {