-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
bases.py.jinja
51 lines (37 loc) · 1.58 KB
/
bases.py.jinja
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
{% include '_header.py.jinja' %}
{% from '_utils.py.jinja' import recursive_types with context %}
# -- template models.py.jinja --
from pydantic import BaseModel
from . import fields, actions
from ._types import FuncType
from .builder import serialize_base64
from ._compat import PYDANTIC_V2, ConfigDict
if TYPE_CHECKING:
from .client import Prisma
_PrismaModelT = TypeVar('_PrismaModelT', bound='_PrismaModel')
class _PrismaModel(BaseModel):
if PYDANTIC_V2:
model_config: ClassVar[ConfigDict] = ConfigDict(
use_enum_values=True,
arbitrary_types_allowed=True,
populate_by_name=True,
)
elif not TYPE_CHECKING:
from ._compat import BaseConfig
class Config(BaseConfig):
use_enum_values: bool = True
arbitrary_types_allowed: bool = True
allow_population_by_field_name: bool = True
json_encoders: Dict[Any, FuncType] = {
fields.Base64: serialize_base64,
}
# TODO: ensure this is required by subclasses
__prisma_model__: ClassVar[str]
{% for model in dmmf.datamodel.models %}
class Base{{ model.name }}(_PrismaModel):
__prisma_model__: ClassVar[Literal['{{ model.name }}']] = '{{ model.name }}' # pyright: ignore[reportIncompatibleVariableOverride]
@classmethod
def prisma(cls: Type[_PrismaModelT], client: Optional['Prisma'] = None) -> 'actions.{{ model.name }}Actions[_PrismaModelT]':
from .client import get_client
return actions.{{ model.name }}Actions[_PrismaModelT](client or get_client(), cls)
{% endfor %}