-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypes.py
More file actions
73 lines (59 loc) · 2.04 KB
/
types.py
File metadata and controls
73 lines (59 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import Any, Literal, TypeVar
from pydantic import BaseModel, ConfigDict, Field
from sqlalchemy import Alias, Table
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm.util import AliasedClass
from sqlalchemy.sql.base import ExecutableOption
Model = TypeVar('Model', bound=DeclarativeBase)
CreateSchema = TypeVar('CreateSchema', bound=BaseModel)
UpdateSchema = TypeVar('UpdateSchema', bound=BaseModel)
# https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#relationship-loader-api
RelationshipLoadingStrategyType = Literal[
'contains_eager',
'defaultload',
'immediateload',
'joinedload',
'lazyload',
'noload',
'raiseload',
'selectinload',
'subqueryload',
# Load
'defer',
'load_only',
'selectin_polymorphic',
'undefer',
'undefer_group',
'with_expression',
]
# https://docs.sqlalchemy.org/en/20/orm/queryguide/columns.html#column-loading-api
ColumnLoadingStrategyType = Literal[
'defer',
'deferred',
'load_only',
'query_expression',
'undefer',
'undefer_group',
'with_expression',
]
LoadStrategies = list[str] | dict[str, RelationshipLoadingStrategyType] | dict[str, ColumnLoadingStrategyType]
JoinType = Literal[
'inner',
'left',
'full',
]
class JoinConfig(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
model: type[Model] | AliasedClass | Alias | Table = Field(
description='The target model, aliased class, alias, or table to join with'
)
join_on: Any = Field(description='The join condition expression (e.g., model.id == other_model.id)')
join_type: JoinType = Field(default='left', description='The type of join to perform')
fill_result: bool = Field(default=False, description='Whether to populate this model to the query result')
JoinConditions = list[str | JoinConfig] | dict[str, JoinType]
LoadOptions = list[ExecutableOption]
SortColumns = str | list[str]
SortOrders = str | list[str] | None