pydoptic-sql 0.0.1.post1.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+
2
+ from dataclasses import dataclass
3
+ from enum import Enum
4
+ from typing import Any, Generic, TypeVar
5
+
6
+ from pydoptic.selector import Prop, PropOpt
7
+ from pydoptic_sql import SqlTable
8
+
9
+ TC = TypeVar('TC', bound=SqlTable, contravariant=True)
10
+
11
+ class Direction(Enum):
12
+ ASC = 'ASC'
13
+ DESC = 'DESC'
14
+
15
+ @dataclass(frozen=True)
16
+ class OrderBy(Generic[TC]):
17
+ """
18
+ A single ORDER BY entry. Unlike `Constraint`, this never needs arity variants (`OrderBy2`, ...)
19
+ since it only ever wraps one column -- ordering by a cross-table comparison isn't a thing. A
20
+ joined query's `_order_by` is instead typed as a union, e.g. `Sequence[OrderBy[TC] | OrderBy[TC1]]`,
21
+ so entries set before a join carry over unchanged and rendering (qualified vs. not) is decided
22
+ by the query class doing the rendering, same as `PropSelect`/`_qualified_label` already work.
23
+ """
24
+ column: Prop[TC, Any] | PropOpt[TC, Any]
25
+ direction: Direction = Direction.ASC
26
+
27
+ def to_sql(self) -> str:
28
+ return f'{self.column.label} {self.direction.value}'