Skip to content

Commit 01b2ac3

Browse files
committed
Ability to use casting for ORDER BY property 🐤
1 parent 446267a commit 01b2ac3

File tree

6 files changed

+247
-427
lines changed

6 files changed

+247
-427
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.13.0 : 2022-06-09
4+
5+
- **Added**: Ability to use casting for `ORDER BY` property
6+
37
## 0.12.1 : 2022-05-10
48

59
- **Fixed**: Corrected cast of JSON fields

duckql/structures/order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Union
33

44
from duckql.functions.base import BaseFunction
5+
from ..structures.cast_operator import CastOperator
56

67
try:
78
from typing import Literal
@@ -18,7 +19,7 @@ class Direction(Enum):
1819
DESC = 'DESC'
1920

2021
obj: Literal['structures.Order'] = 'structures.Order'
21-
property: Union[Property, BaseFunction]
22+
property: Union[Property, BaseFunction, CastOperator]
2223
kind: Direction = Direction.ASC
2324

2425
def to_sql(self) -> str:

duckql/structures/tests/test_order.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from duckql import CastOperator
12
from duckql.properties import Property
23
from duckql.structures import Order
34

@@ -17,3 +18,14 @@ def test_descending():
1718
)
1819

1920
assert str(my_order) == 'users.name DESC'
21+
22+
23+
def test_cast():
24+
my_order = Order(
25+
property=CastOperator(
26+
property=Property(name='users.additional_data -> custom_fields ->> age'),
27+
to=CastOperator.DataType.INT
28+
)
29+
)
30+
31+
assert str(my_order) == "(users.additional_data -> 'custom_fields' ->> 'age')::int ASC"

duckql/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.12.1'
1+
__version__ = '0.13.0'

0 commit comments

Comments
 (0)