> On 27 May 2017, at 12:40, Gwendal Roué <gwendal.r...@gmail.com> wrote:
>
>
>> Le 27 mai 2017 à 11:59, David Hart <da...@hartbit.com
>> <mailto:da...@hartbit.com>> a écrit :
>>
>> I didn’t know that was possible either! Really cool. Even better:
>>
>> if let databaseValueType = T.self as? DatabaseValueConvertible.Type {
>> let databaseValue: DatabaseValue = row.value(named: key.stringValue)
>> return databaseValueType.fromDatabaseValue(databaseValue) as! T
>> } else { … }
>
>
> Yes, that's even more clear like that :-)
>
> And for Encodable support, it works just great (not a single line of
> boilerplate code):
>
> private enum Color: String, DatabaseValueConvertible, Encodable {
> case red, green, blue
> }
>
> private struct EncodableStruct : Persistable, Encodable {
> static let databaseTableName = "myTable"
> let name: String
> let color: Color?
> }
>
> try dbQueue.inDatabase { db in
> try EncodableStruct(name: "Arthur", color: .red).insert(db)
> }
>
> Gwendal
>
As a user of GRDB: 😍
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution