File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,6 +161,16 @@ extension Data: AttributeDecodable {
161161 }
162162}
163163
164+ extension Decimal : AttributeDecodable {
165+
166+ public init ? ( attributeValue: AttributeValue ) {
167+ guard case let . decimal( value) = attributeValue else {
168+ return nil
169+ }
170+ self = value
171+ }
172+ }
173+
164174extension Float : AttributeDecodable {
165175
166176 public init ? ( attributeValue: AttributeValue ) {
Original file line number Diff line number Diff line change @@ -192,14 +192,6 @@ internal extension ModelDataDecoder {
192192 throw DecodingError . dataCorrupted ( DecodingError . Context ( codingPath: codingPath, debugDescription: " Cannot decode \( type) from identifier \( id) " ) )
193193 }
194194 return value as! T
195- } else if type == Data . self {
196- return try decodeAttribute ( Data . self, forKey: key) as! T
197- } else if type == Date . self {
198- return try decodeAttribute ( Date . self, forKey: key) as! T
199- } else if type == UUID . self {
200- return try decodeAttribute ( UUID . self, forKey: key) as! T
201- } else if type == URL . self {
202- return try decodeAttribute ( URL . self, forKey: key) as! T
203195 } else if let decodableType = type as? AttributeDecodable . Type {
204196 return try decodeAttribute ( decodableType, forKey: key) as! T
205197 } else {
Original file line number Diff line number Diff line change @@ -147,3 +147,8 @@ extension URL: AttributeEncodable {
147147
148148 public var attributeValue : AttributeValue { . url( self ) }
149149}
150+
151+ extension Decimal : AttributeEncodable {
152+
153+ public var attributeValue : AttributeValue { . decimal( self ) }
154+ }
Original file line number Diff line number Diff line change @@ -123,15 +123,7 @@ internal extension ModelDataEncoder {
123123
124124 func setEncodable < T: Encodable > ( _ value: T , forKey key: PropertyKey ) throws {
125125
126- if let data = value as? Data {
127- try setAttribute ( data. attributeValue, forKey: key)
128- } else if let date = value as? Date {
129- try setAttribute ( date. attributeValue, forKey: key)
130- } else if let uuid = value as? UUID {
131- try setAttribute ( uuid. attributeValue, forKey: key)
132- } else if let url = value as? URL {
133- try setAttribute ( url. attributeValue, forKey: key)
134- } else if let encodable = value as? AttributeEncodable {
126+ if let encodable = value as? AttributeEncodable {
135127 try setAttribute ( encodable. attributeValue, forKey: key)
136128 } else {
137129 // encode using Encodable, container should write directly.
You can’t perform that action at this time.
0 commit comments