Flutter - Sqflite Query Values Match Any Values In List
Trinh Le Aug 11, 2021 2021-08-11T09:05:00+07:00
Aug 15, 2021 2021-08-15T15:29:30+07:00 1 min
As you may know, in order to query values that match any values in a predefined list, you can use the IN
check.
For example:
SELECT *
FROM categories
WHERE id IN (1, 2, 3, 4)
It’s easy for raw SQL but how to achieve that using Sqflite
?
1
2
3
4
5
6
final ids = [1, 2, 3, 4]
db.query(
'categories',
where: "id IN (${ids.map((_) => '?').join(', ')})",
whereArgs: ids,
);
The main point is to generate enough ?
placeholders in your where
statement and you’re good to go!
Happy coding! 💻
This post is licensed under CC BY 4.0 by the author.