Skip to content

Commit

Permalink
Merge pull request #1 from kjessup/codablecolumnsupport
Browse files Browse the repository at this point in the history
codable columns
  • Loading branch information
kjessup authored Feb 25, 2018
2 parents b80e3fb + c6c5cb1 commit 8921654
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 8921654

Please sign in to comment.