Data system refactor and core redesign for public.

Redesigned data and core systems to be public-capable.
This commit is contained in:
2021-09-12 11:04:49 +03:00
parent 459a728968
commit 0183b63c55
33 changed files with 1170 additions and 790 deletions

59
bot/data/conditions.py Normal file
View File

@@ -0,0 +1,59 @@
from .connection import _replace_char
class Condition:
"""
ABC representing a selection condition.
"""
__slots__ = ()
def apply(self, key, values, conditions):
raise NotImplementedError
class NOT(Condition):
__slots__ = ('value',)
def __init__(self, value):
self.value = value
def apply(self, key, values, conditions):
item = self.value
if isinstance(item, (list, tuple)):
if item:
conditions.append("{} NOT IN ({})".format(key, ", ".join([_replace_char] * len(item))))
values.extend(item)
else:
raise ValueError("Cannot check an empty iterable!")
else:
conditions.append("{}!={}".format(key, _replace_char))
values.append(item)
class GEQ(Condition):
__slots__ = ('value',)
def __init__(self, value):
self.value = value
def apply(self, key, values, conditions):
item = self.value
if isinstance(item, (list, tuple)):
raise ValueError("Cannot apply GEQ condition to a list!")
else:
conditions.append("{} >= {}".format(key, _replace_char))
values.append(item)
class Constant(Condition):
__slots__ = ('value',)
def __init__(self, value):
self.value = value
def apply(self, key, values, conditions):
conditions.append("{} {}".format(key, self.value))
NULL = Constant('IS NULL')
NOTNULL = Constant('IS NOT NULL')