Coverage for src/prisma/_types.py: 100%
37 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from __future__ import annotations
3from typing import Any, Type, Tuple, Mapping, TypeVar, Callable, Coroutine
4from typing_extensions import (
5 Literal as Literal,
6 NewType,
7 Protocol as Protocol,
8 TypedDict as TypedDict,
9 TypeGuard as TypeGuard,
10 get_args as get_args,
11 runtime_checkable as runtime_checkable,
12)
14import httpx
15from pydantic import BaseModel
17Method = Literal['GET', 'POST']
19CallableT = TypeVar('CallableT', bound='FuncType')
20BaseModelT = TypeVar('BaseModelT', bound=BaseModel)
22# TODO: use a TypeVar everywhere
23FuncType = Callable[..., object]
24CoroType = Callable[..., Coroutine[Any, Any, object]]
27@runtime_checkable
28class InheritsGeneric(Protocol):
29 __orig_bases__: Tuple['_GenericAlias']
32class _GenericAlias(Protocol):
33 __origin__: Type[object]
36PrismaMethod = Literal[
37 # raw queries
38 'query_raw',
39 'query_first',
40 'execute_raw',
41 # mutatitive queries
42 'create',
43 'delete',
44 'update',
45 'upsert',
46 'create_many',
47 'delete_many',
48 'update_many',
49 # read queries
50 'count',
51 'group_by',
52 'find_many',
53 'find_first',
54 'find_first_or_raise',
55 'find_unique',
56 'find_unique_or_raise',
57]
60# NOTE: we don't support some options as their type hints are not publicly exposed
61# https://github.com/encode/httpx/discussions/1977
62class HttpConfig(TypedDict, total=False):
63 app: Callable[[Mapping[str, Any], Any], Any]
64 http1: bool
65 http2: bool
66 limits: httpx.Limits
67 timeout: None | float | httpx.Timeout
68 trust_env: bool
69 max_redirects: int
72SortMode = Literal['default', 'insensitive']
73SortOrder = Literal['asc', 'desc']
75MetricsFormat = Literal['json', 'prometheus']
78class _DatasourceOverrideOptional(TypedDict, total=False):
79 env: str
80 name: str
83class DatasourceOverride(_DatasourceOverrideOptional):
84 url: str
87class _DatasourceOptional(TypedDict, total=False):
88 env: str
89 source_file_path: str | None
92class Datasource(_DatasourceOptional):
93 name: str
94 url: str
97TransactionId = NewType('TransactionId', str)