Skip to content

Commit 0a9dcb7

Browse files
committed
Support type overrides with test coveragfixtures
Also updated tests to the latest sqlc version
1 parent 38c7e0d commit 0a9dcb7

File tree

48 files changed

+328
-48
lines changed

Some content is hidden

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

48 files changed

+328
-48
lines changed

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

examples/src/ondeck/venue.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: venue.sql
55
import dataclasses
66
from typing import AsyncIterator, List, Optional

0 commit comments

Comments
 (0)