In my previous question: How to create a filter that does the SQL equivalent of WHERE ... IN for SQLite.Swift
I asked how to how to do a WHERE...IN in swift.
Now, how do I filter optional Expressions?
I have a versioned database that allows me to add columns to tables after it was created. And to achieve that, I created the column with
static let timeTag = Expression<String?>("timeTag")
and then called
try DB.run("PRAGMA user_version = 2")
let query = table.addColumn(timeTag)
let _ = try DB.run(query)
all that works and the table does indeed have that column and I can add data to the column and etc.
usually when I need to filter in other columns, I do
table.filter(self.id == id && self.name == name)
and when I need to do a where in,
table.filter((myNameArray.contains(self.name))
now I want to filter for the timeTag column with an array timeTagArray
which is an array of wanted timeTags to look for. I tried
table.filter(timeTagArray.contains(self.timeTag))
and the table example:
+----+-------+-----------+
| id | name | timetag |
+----+-------+-----------+
| 1 | Joe | Morning |
+----+-------+-----------+
| 2 | Alan | Afternoon |
+----+-------+-----------+
| 3 | Brad | Morning |
+----+-------+-----------+
| 4 | Ian | Evening |
+----+-------+-----------+
| 5 | Louis | Midnight |
+----+-------+-----------+
if my timeTagArray = ["Morning", "Midnight"]
then I should get back rows 1, 3, 5.
but it gives me the error that says
Cannot assign value of type 'Expression<Bool?>' (aka 'Expression<Optional<Bool>>') to type 'Expression<Bool>'