From cea032ecb83a589be94860f6045c55533237c529 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 3 Oct 2017 22:07:57 +0200 Subject: Unique index on tags as a functional one. See also: https://github.com/coleifer/peewee/issues/1357 --- archivist/peewee_ext.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'archivist/peewee_ext.py') diff --git a/archivist/peewee_ext.py b/archivist/peewee_ext.py index 40fe5e7..ff03861 100644 --- a/archivist/peewee_ext.py +++ b/archivist/peewee_ext.py @@ -1,4 +1,4 @@ -from peewee import Field +from peewee import Field, SQL from itertools import starmap from functools import reduce @@ -42,3 +42,18 @@ class EnumField(Field): def python_value(self, value): return value if value is None else self._enum_value(value) +class SQLIndex(SQL): + """Ugly hack to allow arbitrary index creation.""" + def __init__(self, field, sql): + self.field = field + super().__init__(sql) + + def clone_base(self): + return SQLWithField(field, self.value) + + @property + def db_column(self): + return self.field + + def as_entity(self): + return self -- cgit v1.2.3-54-g00ecf