Skip to content

Commit

Permalink
codable columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Jessup committed Feb 25, 2018
1 parent b80e3fb commit c6c5cb1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/PerfectSQLite/SQLiteCRUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class SQLiteCRUDRowReader<K : CodingKey>: KeyedDecodingContainerProtocol {
throw CRUDDecoderError("Invalid Date string \(str).")
}
return date as! T
case .codable:
guard let data = statement.columnText(position: columnPosition(key)).data(using: .utf8) else {
throw CRUDDecoderError("Unsupported type: \(type) for key: \(key.stringValue)")
}
return try JSONDecoder().decode(type, from: data)
}
}
func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey {
Expand Down Expand Up @@ -278,6 +283,8 @@ class SQLiteGenDelegate: SQLGenDelegate {
typeName = "TEXT"
case .date:
typeName = "TEXT"
case .codable:
typeName = "TEXT"
}
}
let addendum: String
Expand Down

0 comments on commit c6c5cb1

Please sign in to comment.