Open tylerbrandt opened 2 years ago
I ran into the same issue. It seems that Swift's Codable implementation defaults to that container type when it doesn't quite know what the generic type V is, despite not generating a complier error.
You can get Swift to generate a complier error like so....
let connection = try Database.getConnection()
let id = Expression<String>("id")
let windowTable = CaptureWindow.getTable()
do {
if let row = try connection.pluck(windowTable.filter(id == windowID)) {
let window = try row.decode()
return window
}
} catch {
print(error.localizedDescription)
}
return nil
To resolve, I specified the type.
let window: CaptureWindow = try row.decode()
(Note: I'm working on a project that already had a number of Codable extensions, which might play a role in this issue. I had to comment some of them out to get SQLite.swift Codable working. You might want to check for extensions in your project as well.)
Just ran into this again, even when specifying the type as indicated above. To resolve, I switched to...
let session = try row.decode() as CaptureSession
Build Information
SQLite.swift version: 0.13.2 (installed with Xcode "Add packages...") Xcode version: 13.2.1 macOS version: 12.3
Description of issue
When I try to decode a
Codable
type usingdb.prepare
and iterating over the results, it works. However, when usedb.pluck
to fetch at most one of the same type, it fails with the error:Playground code to reproduce the error above (I created as a new page in the SQLite.swift playground):
Looking at the source code for the string in question, it seems like this is triggering the
SQLiteDecoder.singleValueContainer
method, and the error is being thrown intentionally, but this limitation isn't noted in the docs so it's possible I'm doing something wrong.