Skip to content

Commit 2111971

Browse files
authored
Overrites (#105)
* feat(core): add overrides for Python type imports (#feature/overrides) * feat(core): add overrides for Python type imports (#feature/overrides) * testing * feat(models/builders): Add IsOverwrite field in core.PyType struct (feature/overrides) * Enabling Ruff Preview (#104) * enable preview * fix FURB152 * fix ruf errors * enable ruff preview * fragment * ci format=github * fix pipeline errors * missing queries file * feat(core): add overrides for Python type imports (#feature/overrides) * feat(core): add overrides for Python type imports (#feature/overrides) * testing * feat(models/builders): Add IsOverwrite field in core.PyType struct (feature/overrides) * type override done, adding tests * feat(asyncpg): modify arg name if type has an override (feature/overrides) * docs: Add documentation for type overrides in sqlc.yaml (feature/overrides) * added tests * fragment
1 parent a3cf45c commit 2111971

File tree

80 files changed

+8598
-2950
lines changed

Some content is hidden

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

80 files changed

+8598
-2950
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Added
2+
body: Added support for type overrides, allowing users to specify their own python types for specific sql types.
3+
time: 2025-05-26T01:07:13.9596774+02:00
4+
custom:
5+
Author: rayakame
6+
PR: "105"

.coverage

20 KB
Binary file not shown.

README.md

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,44 @@ sql:
3838
More options at the [`sqlc` config reference](https://docs.sqlc.dev/en/stable/reference/config.html)
3939

4040
## Configuration Options
41-
| Name | Type | Required | Description |
42-
|----------------------------------|--------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
43-
| `package` | string | yes | The name of the package where the generated files will be located |
44-
| `emit_init_file` | bool | yes | If set to to `false` there will be no `__init__.py` file created in the package that you specified. Only set this to false if you know that you already have a `__init__.py` file otherwise the generated code wont work. |
45-
| `sql_driver` | string | no | The name of the sql driver you want to use. Defaults to `aiosqlite`. Valid options are listed [here](#feature-support) |
46-
| `model_type` | string | no | The model type you want to use. This can be one of `dataclass`, `msgspec` or `attrs`. Defaults to `dataclass` |
47-
| `initialisms` | list[string] | no | An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. |
48-
| `emit_exact_table_names` | bool | no | If `true`, model names will mirror table names. Otherwise sqlc attempts to singularize plural table names. |
49-
| `emit_classes` | bool | no | If `true`, every query function will be put into a class called `Querier`. Otherwise every function will be a standalone function. |
50-
| `inflection_exclude_table_names` | list[string] | no | An array of table names that should not be turned singular. Only applies if `emit_exact_table_names` is `false`. |
51-
| `omit_unused_models` | bool | no | If set to `true` and there are models/tables that are not used in any query, they wont be turned into models. |
52-
| `docstrings` | string | no | If set, there will be docstrings generated in the selected format. This can be one of `google`, `numpy`, `pep257` and `none`. `none` will not generate any docstrings. |
53-
| `docstrings_emit_sql` | bool | no | If set to `false` the SQL code for each query wont be included in the docstrings. This defaults to `true` but is not used when `docstrings` is not set or set to `none` |
54-
| `query_parameter_limit` | integer | no | Not yet implemented. |
55-
| `speedups` | bool | no | If set to `true` the plugin will use other librarys for type conversion. Needs extra dependecys to be installed. This option currently only affects `sqlite3` & `aiosqlite` and uses the library `ciso8601` |
56-
| `debug` | bool | no | If set to `true`, there will be debug logs generated into a `log.txt` file when executing `sqlc generate`. Defaults to `false` |
41+
| Name | Type | Required | Description |
42+
|----------------------------------|----------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
43+
| `package` | string | yes | The name of the package where the generated files will be located |
44+
| `emit_init_file` | bool | yes | If set to to `false` there will be no `__init__.py` file created in the package that you specified. Only set this to false if you know that you already have a `__init__.py` file otherwise the generated code wont work. |
45+
| `sql_driver` | string | no | The name of the sql driver you want to use. Defaults to `aiosqlite`. Valid options are listed [here](#feature-support) |
46+
| `model_type` | string | no | The model type you want to use. This can be one of `dataclass`, `msgspec` or `attrs`. Defaults to `dataclass` |
47+
| `initialisms` | list[string] | no | An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. |
48+
| `emit_exact_table_names` | bool | no | If `true`, model names will mirror table names. Otherwise sqlc attempts to singularize plural table names. |
49+
| `emit_classes` | bool | no | If `true`, every query function will be put into a class called `Querier`. Otherwise every function will be a standalone function. |
50+
| `inflection_exclude_table_names` | list[string] | no | An array of table names that should not be turned singular. Only applies if `emit_exact_table_names` is `false`. |
51+
| `omit_unused_models` | bool | no | If set to `true` and there are models/tables that are not used in any query, they wont be turned into models. |
52+
| `docstrings` | string | no | If set, there will be docstrings generated in the selected format. This can be one of `google`, `numpy`, `pep257` and `none`. `none` will not generate any docstrings. |
53+
| `docstrings_emit_sql` | bool | no | If set to `false` the SQL code for each query wont be included in the docstrings. This defaults to `true` but is not used when `docstrings` is not set or set to `none` |
54+
| `query_parameter_limit` | integer | no | Not yet implemented. |
55+
| `speedups` | bool | no | If set to `true` the plugin will use other librarys for type conversion. Needs extra dependecys to be installed. This option currently only affects `sqlite3` & `aiosqlite` and uses the library `ciso8601` |
56+
| `overrides` | list[Override] | no | A list of [type overrides](#type-overrides). |
57+
| `debug` | bool | no | If set to `true`, there will be debug logs generated into a `log.txt` file when executing `sqlc generate`. Defaults to `false` |
58+
59+
### Type Overrides
60+
Similar to `sqlc-gen-go` this plugin supports overriding types with your own. You can either override the type of every column that has a specific sql type, or you can overwrite the type of specific columns.
61+
62+
```yaml
63+
# filename: sqlc.yaml
64+
# ...
65+
options:
66+
# ...
67+
overrides:
68+
- db_type: text
69+
py_type:
70+
import: collections
71+
package: UserString
72+
type: UserString
73+
- column: table_name.text_column
74+
py_type:
75+
import: collections
76+
type: collections.UserString
77+
78+
```
5779

5880
## Feature Support
5981
Every [sqlc macro](https://docs.sqlc.dev/en/latest/reference/macros.html) is supported.

0 commit comments

Comments
 (0)