1.9 KiB
1.9 KiB
Translating the search DSL
Defining and translating the Search DSL for the Subscriber Search Service.
Searches
A search is a collection of groupings
@dataclasses.dataclass
class Search:
conditions: typing.List[Group]
A grouping is a collection of conditions
class GroupType(enum.Enum):
AND = 1
# TODO: OR = 2
@dataclasses.dataclass
class Group:
group_type: GroupType
conditions: typing.List[Condition]
A condition is a boolean expression applied to a field
@dataclasses.dataclass
class Condition:
field: Field
operator: str
value: typing.Optional[str]
A field refers to a specific database field somewhere in our system
class Database(enum.Enum):
AppDB = 1
Analytics = 2
@dataclasses.dataclass
class FieldType:
name: str
@dataclasses.dataclass
class Field:
name: str
column: str
table: str
database: Database
Allowable conditions
Decisions
Should the input type presented to the end-user be tied to the database field or the conditional operator?
Seems it should be the operator, as an "equals" operator would match a single
value, whereas an "in" operator would match against multiple. That said, it
could be parameterized by the field's type (e.g. a tag has type str
, its
"equals" operator has type str
, its "in" operator has type List[str]
).
Code
import dataclasses
import enum
import typing
<<field>>
<<condition>>
<<group>>
<<search>>