-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor, so we have an
Arrow
function
- Loading branch information
1 parent
a58663b
commit 976f3ef
Showing
3 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import typing as t | ||
|
||
from piccolo.querystring import QueryString | ||
from piccolo.utils.encoding import dump_json | ||
|
||
if t.TYPE_CHECKING: | ||
from piccolo.columns.column_types import JSONB | ||
|
||
|
||
class Arrow(QueryString): | ||
""" | ||
Functionally this is basically the same as ``QueryString``, we just need | ||
``Query._process_results`` to be able to differentiate it from a normal | ||
``QueryString`` just in case the user specified | ||
``.output(load_json=True)``. | ||
""" | ||
|
||
def __init__(self, column: JSONB, key: str, alias: t.Optional[str] = None): | ||
super().__init__("{} -> {}", column, key, alias=alias) | ||
|
||
def clean_value(self, value: t.Any): | ||
if not isinstance(value, (str, QueryString)): | ||
value = dump_json(value) | ||
return value | ||
|
||
def __eq__(self, value) -> QueryString: # type: ignore[override] | ||
value = self.clean_value(value) | ||
return QueryString("{} = {}", self, value) | ||
|
||
def __ne__(self, value) -> QueryString: # type: ignore[override] | ||
value = self.clean_value(value) | ||
return QueryString("{} != {}", self, value) | ||
|
||
def eq(self, value) -> QueryString: | ||
return self.__eq__(value) | ||
|
||
def ne(self, value) -> QueryString: | ||
return self.__ne__(value) |