Skip to content

Commit dba6e76

Browse files
Merge pull request #8 from enveritas/feature/type-overrides
Support type overrides in addition to column overrides
2 parents 38c7e0d + 619f15b commit dba6e76

File tree

50 files changed

+425
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+425
-57
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
go-version: '1.23.5'
1616
- uses: sqlc-dev/setup-sqlc@v4
1717
with:
18-
sqlc-version: '1.29.0'
18+
sqlc-version: '1.30.0'
1919
- run: make
2020
- run: make test
2121
- run: sqlc diff

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,51 @@ class Status(str, enum.Enum):
9999
OPEN = "op!en"
100100
CLOSED = "clo@sed"
101101
```
102+
103+
### Override Column Types
104+
105+
Option: `overrides`
106+
107+
You can override the SQL to Python type mapping for specific columns or database types using the `overrides` option. This is useful for columns with JSON data or other custom types.
108+
109+
Example configuration:
110+
111+
```yaml
112+
options:
113+
package: authors
114+
emit_pydantic_models: true
115+
overrides:
116+
- column: "some_table.payload"
117+
py_import: "my_lib.models"
118+
py_type: "Payload"
119+
- db_type: "jsonb"
120+
py_import: "my_lib.models"
121+
py_type: "Payload"
122+
```
123+
124+
This will:
125+
1. Override the column `payload` in `some_table` to use the type `Payload`
126+
2. Override any column with the database type `jsonb` to use the type `Payload`
127+
3. Add an import for `my_lib.models` to the models file
128+
129+
Example output:
130+
131+
```python
132+
# Code generated by sqlc. DO NOT EDIT.
133+
# versions:
134+
# sqlc v1.30.0
135+
136+
import datetime
137+
import pydantic
138+
from typing import Any
139+
140+
import my_lib.models
141+
142+
143+
class SomeTable(pydantic.BaseModel):
144+
id: int
145+
created_at: datetime.datetime
146+
payload: my_lib.models.Payload
147+
```
148+
149+
This is similar to the [overrides functionality in the Go version of sqlc](https://docs.sqlc.dev/en/stable/howto/overrides.html#overriding-types).

examples/src/authors/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55
from typing import Optional
66

examples/src/authors/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query.sql
55
from typing import AsyncIterator, Iterator, Optional
66

examples/src/booktest/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55
import datetime
66
import enum

examples/src/booktest/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query.sql
55
import dataclasses
66
import datetime

examples/src/jets/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55

66

examples/src/jets/query-building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query-building.sql
55
from typing import AsyncIterator, Optional
66

examples/src/ondeck/city.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: city.sql
55
from typing import AsyncIterator, Optional
66

examples/src/ondeck/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55
import datetime
66
import enum

0 commit comments

Comments
 (0)