Coverage for sqlalchemy_crud_plus\types.py: 100%
24 statements
« prev ^ index » next coverage.py v7.11.1, created at 2025-11-26 11:02 +0800
« prev ^ index » next coverage.py v7.11.1, created at 2025-11-26 11:02 +0800
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3from __future__ import annotations
5from typing import Any, Literal, TypeVar
7from pydantic import BaseModel, ConfigDict, Field
8from sqlalchemy import Alias, Table
9from sqlalchemy.orm import DeclarativeBase
10from sqlalchemy.orm.util import AliasedClass
11from sqlalchemy.sql.base import ExecutableOption
13Model = TypeVar('Model', bound=DeclarativeBase)
14CreateSchema = TypeVar('CreateSchema', bound=BaseModel)
15UpdateSchema = TypeVar('UpdateSchema', bound=BaseModel)
17# https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#relationship-loader-api
18RelationshipLoadingStrategyType = Literal[
19 'contains_eager',
20 'defaultload',
21 'immediateload',
22 'joinedload',
23 'lazyload',
24 'noload',
25 'raiseload',
26 'selectinload',
27 'subqueryload',
28 # Load
29 'defer',
30 'load_only',
31 'selectin_polymorphic',
32 'undefer',
33 'undefer_group',
34 'with_expression',
35]
37# https://docs.sqlalchemy.org/en/20/orm/queryguide/columns.html#column-loading-api
38ColumnLoadingStrategyType = Literal[
39 'defer',
40 'deferred',
41 'load_only',
42 'query_expression',
43 'undefer',
44 'undefer_group',
45 'with_expression',
46]
48LoadStrategies = list[str] | dict[str, RelationshipLoadingStrategyType] | dict[str, ColumnLoadingStrategyType]
50JoinType = Literal[
51 'inner',
52 'left',
53 'full',
54]
57class JoinConfig(BaseModel):
58 model_config = ConfigDict(arbitrary_types_allowed=True)
60 model: type[Model] | AliasedClass | Alias | Table = Field(
61 description='The target model, aliased class, alias, or table to join with'
62 )
63 join_on: Any = Field(description='The join condition expression (e.g., model.id == other_model.id)')
64 join_type: JoinType = Field(default='left', description='The type of join to perform')
65 fill_result: bool = Field(default=False, description='Whether to populate this model to the query result')
68JoinConditions = list[str | JoinConfig] | dict[str, JoinType]
70LoadOptions = list[ExecutableOption]
72SortColumns = str | list[str]
73SortOrders = str | list[str] | None