summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archivist/model.py1
-rw-r--r--archivist/peewee_ext.py3
-rw-r--r--archivist/peewee_fixes.py15
3 files changed, 17 insertions, 2 deletions
diff --git a/archivist/model.py b/archivist/model.py
index 5af743b..4a6a97b 100644
--- a/archivist/model.py
+++ b/archivist/model.py
@@ -9,6 +9,7 @@ from pkg_resources import resource_filename
from .prefixes import query_pseudo_prefix
from .peewee_ext import EnumField
+from .peewee_fixes import * # dummy to force evaluation of those fixes
db = SqliteExtDatabase('test.db', pragmas=[('foreign_keys', 'ON')])
db.load_extension(resource_filename(__name__, 'sqlext/closure'))
diff --git a/archivist/peewee_ext.py b/archivist/peewee_ext.py
index f835dc3..40fe5e7 100644
--- a/archivist/peewee_ext.py
+++ b/archivist/peewee_ext.py
@@ -1,5 +1,4 @@
-from playhouse.sqlite_ext import VirtualModel, VirtualIntegerField, VirtualCharField
-from peewee import Field, OP, DJANGO_MAP, ForeignKeyField, ReverseRelationDescriptor, Expression, Query
+from peewee import Field
from itertools import starmap
from functools import reduce
diff --git a/archivist/peewee_fixes.py b/archivist/peewee_fixes.py
new file mode 100644
index 0000000..ff914da
--- /dev/null
+++ b/archivist/peewee_fixes.py
@@ -0,0 +1,15 @@
+from peewee import QueryCompiler, strip_parens, ForeignKeyField
+
+__all__ = []
+
+def _parse_select_query(self, node, alias_map, conv):
+ clone = node.clone()
+ if not node._explicit_selection:
+ if conv and isinstance(conv, ForeignKeyField):
+ clone._select = (conv.to_field,)
+ else:
+ clone._select = clone.model_class._meta.get_primary_key_fields()
+ sub, params = self.generate_select(clone, alias_map)
+ return '(%s)' % strip_parens(sub), params
+
+QueryCompiler._parse_select_query = _parse_select_query