@@ -34,14 +34,20 @@ post_crud: CRUDPlus[Post] = CRUDPlus(Post)
3434### LoadStrategiesConfig
3535
3636``` python
37- from typing import Union, Dict, List
38-
39- LoadStrategiesConfig = Union[
40- List[str ], # Simple list format
41- Dict[str , str ], # Strategy mapping
42- Dict[str , Dict[str , str ]] # Nested strategies
37+ from typing import Literal
38+
39+ LoadingStrategy = Literal[
40+ ' selectinload' , # SELECT IN loading (recommended for one-to-many)
41+ ' joinedload' , # JOIN loading (recommended for one-to-one)
42+ ' subqueryload' , # Subquery loading (for large datasets)
43+ ' contains_eager' , # Use with explicit JOINs
44+ ' raiseload' , # Prevent lazy loading
45+ ' noload' , # Don't load relationship
4346]
4447
48+ # Configuration for relationship loading strategies
49+ LoadStrategiesConfig = list[str ] | dict[str , LoadingStrategy]
50+
4551# Examples
4652load_strategies: LoadStrategiesConfig = [' posts' , ' profile' ]
4753load_strategies: LoadStrategiesConfig = {
@@ -53,13 +59,18 @@ load_strategies: LoadStrategiesConfig = {
5359### JoinConditionsConfig
5460
5561``` python
56- from typing import Union, Dict, List
62+ from typing import Literal
5763
58- JoinConditionsConfig = Union[
59- List[str ], # Simple list format
60- Dict[str , str ] # JOIN type mapping
64+ JoinType = Literal[
65+ ' inner' , # INNER JOIN
66+ ' left' , # LEFT OUTER JOIN
67+ ' right' , # RIGHT OUTER JOIN
68+ ' full' , # FULL OUTER JOIN
6169]
6270
71+ # Configuration for JOIN conditions
72+ JoinConditionsConfig = list[str ] | dict[str , JoinType]
73+
6374# Examples
6475join_conditions: JoinConditionsConfig = [' posts' , ' profile' ]
6576join_conditions: JoinConditionsConfig = {
@@ -71,10 +82,9 @@ join_conditions: JoinConditionsConfig = {
7182### QueryOptions
7283
7384``` python
74- from typing import List, Any
75- from sqlalchemy.orm import Load
85+ from sqlalchemy.sql.base import ExecutableOption
7686
77- QueryOptions = List[Load ]
87+ QueryOptions = list[ExecutableOption ]
7888
7989# Example
8090from sqlalchemy.orm import selectinload, joinedload
@@ -85,6 +95,8 @@ load_options: QueryOptions = [
8595]
8696```
8797
98+ ## 工具类型
99+
88100### 常用过滤器模式
89101
90102``` python
@@ -96,9 +108,9 @@ age__le: int = 60
96108status__ne: int = 0
97109
98110# Range operators
99- id__in: List [int ] = [1 , 2 , 3 , 4 , 5 ]
100- status__not_in: List [int ] = [0 , - 1 ]
101- age__between: List [int ] = [30 , 40 ]
111+ id__in: list [int ] = [1 , 2 , 3 , 4 , 5 ]
112+ status__not_in: list [int ] = [0 , - 1 ]
113+ age__between: list [int ] = [30 , 40 ]
102114
103115# String operators
104116name__like: str = ' %张%'
@@ -111,51 +123,16 @@ deleted_at__is: None = None
111123profile_id__is_not: None = None
112124
113125# OR conditions
114- __or__ : Dict [str , List[ Any] ] = {
126+ __or__ : dict [str , Any] = {
115127 ' email__endswith' : [' @gmail.com' , ' @qq.com' ]
116128}
117129```
118130
119- ## 会话类型
120-
121- ### AsyncSession
122-
123- ``` python
124- from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
125-
126- # Session factory type
127- AsyncSessionFactory = async_sessionmaker[AsyncSession]
128-
129- # Usage
130- _async_db_session: AsyncSessionFactory = async_sessionmaker(
131- engine,
132- expire_on_commit = False
133- )
134- ```
135-
136- ## 工具类型
137-
138- ### 主键类型
139-
140- ``` python
141- from typing import Union, Tuple, Any
142-
143- # Single or composite primary key
144- PrimaryKeyType = Union[Any, Tuple[Any, ... ]]
145-
146- # Examples
147- pk: PrimaryKeyType = 1 # Single primary key
148- pk: PrimaryKeyType = (1 , 2 ) # Composite primary key
149- pk: PrimaryKeyType = " uuid-string" # String primary key
150- ```
151-
152131### 排序配置
153132
154133``` python
155- from typing import Union, List
156-
157- SortColumns = Union[str , List[str ]]
158- SortOrders = Union[str , List[str ]]
134+ SortColumns = str | list[str ]
135+ SortOrders = str | list[str ] | None
159136
160137# Examples
161138sort_columns: SortColumns = " created_time"
0 commit comments