Skip to content

Commit 397fe5b

Browse files
committed
docs: add examples of with w/o
1 parent eef4c98 commit 397fe5b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ Option: `emit_pydantic_models`
2626

2727
By default, `sqlc-gen-python` will emit `dataclasses` for the models. If you prefer to use [`pydantic`](https://docs.pydantic.dev/latest/) models, you can enable this option.
2828

29+
with `emit_pydantic_models`
30+
31+
```py
32+
from pydantic import BaseModel
33+
34+
class Author(pydantic.BaseModel):
35+
id: int
36+
name: str
37+
```
38+
39+
without `emit_pydantic_models`
40+
41+
```py
42+
from dataclasses import dataclasses
43+
44+
@dataclasses
45+
class Author:
46+
id: int
47+
name: str
48+
```
49+
2950
### Use `enum.StrEnum` for Enums
3051

3152
Option: `emit_str_enum`
@@ -37,3 +58,21 @@ Option: `emit_str_enum`
3758
This is convenient for type checking and validation, as well as for serialization and deserialization.
3859

3960
By default, `sqlc-gen-python` will emit `(str, enum.Enum)` for the enum classes. If you prefer to use `enum.StrEnum`, you can enable this option.
61+
62+
with `emit_str_enum`
63+
64+
```py
65+
class Status(enum.StrEnum):
66+
"""Venues can be either open or closed"""
67+
OPEN = "op!en"
68+
CLOSED = "clo@sed"
69+
```
70+
71+
without `emit_str_enum` (current behavior)
72+
73+
```py
74+
class Status(str, enum.Enum):
75+
"""Venues can be either open or closed"""
76+
OPEN = "op!en"
77+
CLOSED = "clo@sed"
78+
```

0 commit comments

Comments
 (0)