I have a query with a column that should be aliased
When I try to alias the column, return nil.
this is my code :
func show() {
let cat_table = Table("cat")
let id = Expression<Int>("id")
let cat_text = Expression<String>("text")
do {
let resultSet = try db.prepare(cat_table
.select(id,
cat_text,
cat_table[id].alias(name:"C_ID")))
.map({Model(row: $0)})
for res in resultSet {
print(" Name: \(res.c_id) -- ID: \(res.text) \n")
}
} catch {
fatalError(error.localizedDescription)
}
}
my model :
class Model {
let id: Int
let text: String
let c_id: Int?
init(row: Row) {
do {
id = try row.get(Expression<Int>("id"))
text = try row.get(Expression<String>("text"))
c_id = try? row.get(Expression<Int>("C_ID")) //If i remove the ? it will crash
} catch { fatalError() }
}
init() {
id = 1
text = ""
c_id = 1
}
}
and my table scheme is: cat (id INT, text: TEXT)