e.k
e.k

Reputation: 1363

Filter multiple columns using sqlite.swift?

let part = self.parts.filter(self.deleteStatus == 0).order(self.id.asc)

Above is the query I run to get all the records from local database. Now I want to add more filters like id==5 or name='product' in the filter. But the filter in sqlite.swift doesn't allow more than one expression in filter. How can I add more or filters in the filter method?

Upvotes: 4

Views: 1216

Answers (2)

btraas
btraas

Reputation: 148

Filters can be chained with && (SQLite AND) and || (SQLite OR).

self.filter(deleteStatus == 0 && id == 5 && name == "product")

https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#filter-operators-and-functions

Upvotes: 4

Martheli
Martheli

Reputation: 981

The filter in Sqlite.swift does allow more than one expression; you just chain them together like this:

users.filter(id == 1 %% location == "Office" %% supervisor == "John")

Upvotes: -2

Related Questions