summaryrefslogtreecommitdiff
path: root/archivist/peewee_ext.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archivist/peewee_ext.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/archivist/peewee_ext.py b/archivist/peewee_ext.py
index 9fda66e..80bb6f4 100644
--- a/archivist/peewee_ext.py
+++ b/archivist/peewee_ext.py
@@ -1,6 +1,16 @@
from playhouse.sqlite_ext import VirtualModel, VirtualIntegerField, VirtualCharField
from peewee import Field
+from itertools import starmap
+from functools import reduce
+import operator as op
+
+def sqlite_tuple_in(fields, values):
+ """SQLite does not support (foo, bar) IN ((1,2),(3,4)).
+ So we construct a '(foo = 1 AND bar = 2) OR (foo = 3 AND bar = 4)' monstrum."""
+ subqueries = (reduce(op.and_, starmap(op.eq, zip(fields, value_tuple))) for value_tuple in values)
+ return reduce(op.or_, subqueries)
+
class EnumField(Field):
db_field = 'enum'