mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Replace DatabaseIntRepresentable, DatabaseInt32Representable, DatabaseInt64Representable and DatabaseStringRepresentable with DatabaseRawRepresentable.
This commit is contained in:
1 parent
06031d1c79
commit
fd1067b41f
6 files changed
+58
-177
No files matched your search
@@ -2,6 +2,13 @@ Release Notes
|
||||
=============
|
||||
|
||||
|
||||
## Next Version
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- `DatabaseIntRepresentable`, `DatabaseInt32Representable`, `DatabaseInt64Representable` and `DatabaseStringRepresentable` have been replaced by the single protocol `DatabaseRawRepresentable` ([documentation](https://github.com/groue/GRDB.swift#swift-enums))
|
||||
|
||||
|
||||
## 0.45.1
|
||||
|
||||
Released February 11, 2016
|
||||
|
||||
@@ -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 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* RawRepresentable.swift */; };
|
||||
5605F1721C672E4000235C62 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* RawRepresentable.swift */; };
|
||||
5605F1711C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */; };
|
||||
5605F1721C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseRawRepresentable.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 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
56A238441B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
56A238431B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */; };
|
||||
56A238441B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.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 = "<group>"; };
|
||||
5605F1541C672E4000235C62 /* Row+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+Foundation.swift"; sourceTree = "<group>"; };
|
||||
5605F1551C672E4000235C62 /* StatementArguments+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+Foundation.swift"; sourceTree = "<group>"; };
|
||||
5605F1571C672E4000235C62 /* RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = "<group>"; };
|
||||
5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRawRepresentable.swift; sourceTree = "<group>"; };
|
||||
5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = "<group>"; };
|
||||
5605F1861C69111300235C62 /* SelectStatementSourceTablesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementSourceTablesTests.swift; sourceTree = "<group>"; };
|
||||
5605F1891C6B1A8700235C62 /* SQLCollation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollation.swift; sourceTree = "<group>"; };
|
||||
@@ -350,7 +350,7 @@
|
||||
56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = "<group>"; };
|
||||
56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleSubclassTests.swift; sourceTree = "<group>"; };
|
||||
56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionTests.swift; sourceTree = "<group>"; };
|
||||
56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = "<group>"; };
|
||||
56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRawRepresentableTests.swift; sourceTree = "<group>"; };
|
||||
56A2381E1B9C74A90082EB20 /* DictionaryRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryRowTests.swift; sourceTree = "<group>"; };
|
||||
56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetachedRowTests.swift; sourceTree = "<group>"; };
|
||||
56A238211B9C74A90082EB20 /* SelectStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementTests.swift; sourceTree = "<group>"; };
|
||||
@@ -537,7 +537,7 @@
|
||||
5605F1561C672E4000235C62 /* StandardLibrary */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5605F1571C672E4000235C62 /* RawRepresentable.swift */,
|
||||
5605F1571C672E4000235C62 /* DatabaseRawRepresentable.swift */,
|
||||
5605F1581C672E4000235C62 /* StandardLibrary.swift */,
|
||||
);
|
||||
path = StandardLibrary;
|
||||
@@ -680,12 +680,12 @@
|
||||
56A238191B9C74A90082EB20 /* DatabaseValueConvertible */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56A2381C1B9C74A90082EB20 /* DatabaseRawRepresentableTests.swift */,
|
||||
56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */,
|
||||
56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */,
|
||||
56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */,
|
||||
56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */,
|
||||
56CA21B91BB3FCF7009A04C5 /* NSDataTests.swift */,
|
||||
56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */,
|
||||
);
|
||||
path = DatabaseValueConvertible;
|
||||
sourceTree = "<group>";
|
||||
@@ -1282,7 +1282,7 @@
|
||||
5605F15A1C672E4000235C62 /* CGFloat.swift in Sources */,
|
||||
5605F1641C672E4000235C62 /* NSDate.swift in Sources */,
|
||||
5605F1901C6B1A8700235C62 /* SQLFunction.swift in Sources */,
|
||||
5605F1721C672E4000235C62 /* RawRepresentable.swift in Sources */,
|
||||
5605F1721C672E4000235C62 /* DatabaseRawRepresentable.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 /* RawRepresentableTests.swift in Sources */,
|
||||
56A238441B9C74A90082EB20 /* DatabaseRawRepresentableTests.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 /* RawRepresentableTests.swift in Sources */,
|
||||
56A238431B9C74A90082EB20 /* DatabaseRawRepresentableTests.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 /* RawRepresentable.swift in Sources */,
|
||||
5605F1711C672E4000235C62 /* DatabaseRawRepresentable.swift in Sources */,
|
||||
56A2387B1B9C75030082EB20 /* Configuration.swift in Sources */,
|
||||
5605F1691C672E4000235C62 /* NSString.swift in Sources */,
|
||||
5605F16D1C672E4000235C62 /* Row+Foundation.swift in Sources */,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/// Have your RawRepresentable type adopt DatabaseRawRepresentable and it
|
||||
/// automatically gains DatabaseValueConvertible adoption.
|
||||
///
|
||||
/// enum Color : Int {
|
||||
/// case Red
|
||||
/// case White
|
||||
/// case Rose
|
||||
/// }
|
||||
///
|
||||
/// // Declare DatabaseRawRepresentable adoption:
|
||||
/// extension Color : DatabaseRawRepresentable { }
|
||||
///
|
||||
/// // 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 {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
guard let rawValue = RawValue.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: rawValue)
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
// MARK: - DatabaseIntRepresentable
|
||||
|
||||
/// Have your Int enum adopt DatabaseIntRepresentable and it automatically gains
|
||||
/// DatabaseValueConvertible adoption.
|
||||
///
|
||||
/// // An Int enum:
|
||||
/// enum Color : Int {
|
||||
/// case Red
|
||||
/// case White
|
||||
/// case Rose
|
||||
/// }
|
||||
///
|
||||
/// // Declare DatabaseIntRepresentable adoption:
|
||||
/// extension Color : DatabaseIntRepresentable { }
|
||||
///
|
||||
/// // Gain full GRDB.swift support:
|
||||
/// db.execute("INSERT INTO colors (color) VALUES (?)", [Color.Red])
|
||||
/// let color: Color? = Color.fetchOne(db, "SELECT ...")
|
||||
public protocol DatabaseIntRepresentable : DatabaseValueConvertible {
|
||||
var rawValue: Int { get }
|
||||
init?(rawValue: Int)
|
||||
}
|
||||
|
||||
extension DatabaseIntRepresentable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
guard let int = Int.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DatabaseInt32Representable
|
||||
|
||||
/// Have your Int32 enum adopt DatabaseInt32Representable and it automatically
|
||||
/// gains DatabaseValueConvertible adoption.
|
||||
///
|
||||
/// // An Int enum:
|
||||
/// enum Color : Int32 {
|
||||
/// case Red
|
||||
/// case White
|
||||
/// case Rose
|
||||
/// }
|
||||
///
|
||||
/// // Declare DatabaseInt32Representable adoption:
|
||||
/// extension Color : DatabaseInt32Representable { }
|
||||
///
|
||||
/// // Gain full GRDB.swift support:
|
||||
/// db.execute("INSERT INTO colors (color) VALUES (?)", [Color.Red])
|
||||
/// let color: Color? = Color.fetchOne(db, "SELECT ...")
|
||||
public protocol DatabaseInt32Representable : DatabaseValueConvertible {
|
||||
var rawValue: Int32 { get }
|
||||
init?(rawValue: Int32)
|
||||
}
|
||||
|
||||
extension DatabaseInt32Representable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
guard let int = Int32.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DatabaseInt64Representable
|
||||
|
||||
/// Have your Int64 enum adopt DatabaseInt64Representable and it automatically
|
||||
/// gains DatabaseValueConvertible adoption.
|
||||
///
|
||||
/// // An Int enum:
|
||||
/// enum Color : Int64 {
|
||||
/// case Red
|
||||
/// case White
|
||||
/// case Rose
|
||||
/// }
|
||||
///
|
||||
/// // Declare DatabaseInt64Representable adoption:
|
||||
/// extension Color : DatabaseInt64Representable { }
|
||||
///
|
||||
/// // Gain full GRDB.swift support:
|
||||
/// db.execute("INSERT INTO colors (color) VALUES (?)", [Color.Red])
|
||||
/// let color: Color? = Color.fetchOne(db, "SELECT ...")
|
||||
public protocol DatabaseInt64Representable : DatabaseValueConvertible {
|
||||
var rawValue: Int64 { get }
|
||||
init?(rawValue: Int64)
|
||||
}
|
||||
|
||||
extension DatabaseInt64Representable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
guard let int = Int64.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DatabaseStringRepresentable
|
||||
|
||||
/// Have your String enum adopt DatabaseStringRepresentable and it automatically
|
||||
/// gains DatabaseValueConvertible adoption.
|
||||
///
|
||||
/// // A String enum:
|
||||
/// enum Color : String {
|
||||
/// case Red
|
||||
/// case White
|
||||
/// case Rose
|
||||
/// }
|
||||
///
|
||||
/// // Declare DatabaseIntRepresentable adoption:
|
||||
/// extension Color : DatabaseStringRepresentable { }
|
||||
///
|
||||
/// // Gain full GRDB.swift support:
|
||||
/// db.execute("INSERT StringO colors (color) VALUES (?)", [Color.Red])
|
||||
/// let color: Color? = Color.fetchOne(db, "SELECT ...")
|
||||
public protocol DatabaseStringRepresentable : DatabaseValueConvertible {
|
||||
var rawValue: String { get }
|
||||
init?(rawValue: String)
|
||||
}
|
||||
|
||||
extension DatabaseStringRepresentable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
guard let string = String.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: string)
|
||||
}
|
||||
}
|
||||
@@ -826,11 +826,11 @@ enum Grape : String {
|
||||
}
|
||||
```
|
||||
|
||||
Add conformance to a protocol, and the enum type can be stored and fetched from the database just like other [value types](#values):
|
||||
Add conformance to the `DatabaseRawRepresentable` protocol, and the enum type can be stored and fetched from the database just like other [value types](#values):
|
||||
|
||||
```swift
|
||||
extension Color : DatabaseIntRepresentable { } // DatabaseInt32Representable for Int32, DatabaseInt64Representable for Int64
|
||||
extension Grape : DatabaseStringRepresentable { }
|
||||
extension Color : DatabaseRawRepresentable { }
|
||||
extension Grape : DatabaseRawRepresentable { }
|
||||
|
||||
// Store
|
||||
try db.execute("INSERT INTO wines (grape, color) VALUES (?, ?)",
|
||||
|
||||
+4
-4
@@ -25,10 +25,10 @@ enum Grape : String {
|
||||
case Riesling
|
||||
}
|
||||
|
||||
extension Color32 : DatabaseInt32Representable { }
|
||||
extension Color64 : DatabaseInt64Representable { }
|
||||
extension Color : DatabaseIntRepresentable { }
|
||||
extension Grape : DatabaseStringRepresentable { }
|
||||
extension Color32 : DatabaseRawRepresentable { }
|
||||
extension Color64 : DatabaseRawRepresentable { }
|
||||
extension Color : DatabaseRawRepresentable { }
|
||||
extension Grape : DatabaseRawRepresentable { }
|
||||
|
||||
class RawRepresentableTests: GRDBTestCase {
|
||||
|
||||
Reference in new issue
Block a user