Skip to content
Open
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21.0-rc.2'
go-version: '1.21.0'
- run: make
- uses: actions/upload-artifact@v3
with:
name: sqlc-gen-python
path: plugin/sqlc-gen-python.wasm
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# README
## Usage

```yaml
Expand All @@ -16,6 +17,17 @@ sql:
plugin: py
options:
package: authors
emit_sync_querier: true
emit_async_querier: true
emit_module: false
emit_generators: true
emit_async: false
```

## Multiple packages
If you have have a mono-repository setup you may want to split the output of queries and models. You can achieve this by using the `output_models_file_name`
and `output_querier_file` fields. If `output_models_file_name` is set to `null` for it will not output the `models.py` file. Setting `output_querier_file` to false will prevent outputting any query files. Combining these you can set one codegen to only output models while the other codegen outputs only queries. Make sure the `package` configuration is set equally so the query files import correctly the models.

SQLC needs at least one query, so you may need to add a unused query like the following in your schema and reuse the `schema` as `queries`.
```sql
-- name: Skip :one
SELECT 1;
```
16 changes: 11 additions & 5 deletions internal/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package python

// TODO: Where are these properly documented?
type Config struct {
EmitAsync bool `json:"emit_async"` // Emits async code instead of sync
EmitExactTableNames bool `json:"emit_exact_table_names"`
EmitSyncQuerier bool `json:"emit_sync_querier"`
EmitAsyncQuerier bool `json:"emit_async_querier"`
Package string `json:"package"`
Out string `json:"out"`
EmitGenerators bool `json:"emit_generators"` // Will we use generators or lists, defaults to true
EmitModule bool `json:"emit_module"` // If true emits functions in module, else wraps in a class.
EmitPydanticModels bool `json:"emit_pydantic_models"`
QueryParameterLimit *int32 `json:"query_parameter_limit"`
EmitSyncQuerier bool `json:"emit_sync_querier"` // DEPRECATED ALIAS FOR: emit_type = 'class', emit_generators = True
EmitAsyncQuerier bool `json:"emit_async_querier"` // DEPRECATED ALIAS FOR: emit_type = 'class', emit_generators = True
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names"`
Out string `json:"out"`
OutputModelsFileName *string `json:"output_models_file_name,omitempty"` // Can be string or null to exclude generating models file
OutputQuerierFile bool `json:"output_querier_file,omitempty"` // Skips outputting queries
Package string `json:"package"`
QueryParameterLimit *int32 `json:"query_parameter_limit"`
}
Loading