diff --git a/internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml b/internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml index 180ce29..8cf3530 100644 --- a/internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml +++ b/internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/enum_with_eq/db/__init__.py b/internal/endtoend/testdata/enum_with_eq/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/internal/endtoend/testdata/enum_with_eq/db/models.py b/internal/endtoend/testdata/enum_with_eq/db/models.py new file mode 100644 index 0000000..a49e068 --- /dev/null +++ b/internal/endtoend/testdata/enum_with_eq/db/models.py @@ -0,0 +1,20 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.27.0 +import enum +import pydantic +from typing import Optional + + +class Operator(str, enum.Enum): + EQ = "=" + GT = ">" + LT = "<" + GTEQ = ">=" + LTEQ = "<=" + + +class Operation(pydantic.BaseModel): + a: Optional[int] + b: Optional[int] + operation: Optional[Operator] diff --git a/internal/endtoend/testdata/enum_with_eq/db/query.py b/internal/endtoend/testdata/enum_with_eq/db/query.py new file mode 100644 index 0000000..1dc94d3 --- /dev/null +++ b/internal/endtoend/testdata/enum_with_eq/db/query.py @@ -0,0 +1,43 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.27.0 +# source: query.sql +from typing import AsyncIterator, Iterator + +import sqlalchemy +import sqlalchemy.ext.asyncio + +from db import models + + +LIST = """-- name: list \\:many +SELECT a, b, operation FROM operations +""" + + +class Querier: + def __init__(self, conn: sqlalchemy.engine.Connection): + self._conn = conn + + def list(self) -> Iterator[models.Operation]: + result = self._conn.execute(sqlalchemy.text(LIST)) + for row in result: + yield models.Operation( + a=row[0], + b=row[1], + operation=row[2], + ) + + +class AsyncQuerier: + def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): + self._conn = conn + + async def list(self) -> AsyncIterator[models.Operation]: + result = await self._conn.stream(sqlalchemy.text(LIST)) + async for row in result: + yield models.Operation( + a=row[0], + b=row[1], + operation=row[2], + ) diff --git a/internal/endtoend/testdata/enum_with_eq/query.sql b/internal/endtoend/testdata/enum_with_eq/query.sql new file mode 100644 index 0000000..1ec11b7 --- /dev/null +++ b/internal/endtoend/testdata/enum_with_eq/query.sql @@ -0,0 +1,2 @@ +-- name: list :many +SELECT * FROM operations; diff --git a/internal/endtoend/testdata/enum_with_eq/schema.sql b/internal/endtoend/testdata/enum_with_eq/schema.sql new file mode 100644 index 0000000..24ee8d7 --- /dev/null +++ b/internal/endtoend/testdata/enum_with_eq/schema.sql @@ -0,0 +1,13 @@ +CREATE TYPE operator AS ENUM ( + '=', + '>', + '<', + '>=', + '<=' +); + +CREATE TABLE operations ( + a int, + b int, + operation operator +); diff --git a/internal/endtoend/testdata/enum_with_eq/sqlc.yaml b/internal/endtoend/testdata/enum_with_eq/sqlc.yaml new file mode 100644 index 0000000..8cf3530 --- /dev/null +++ b/internal/endtoend/testdata/enum_with_eq/sqlc.yaml @@ -0,0 +1,18 @@ +version: '2' +plugins: +- name: py + wasm: + url: file://../../../../bin/sqlc-gen-python.wasm + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" +sql: +- schema: schema.sql + queries: query.sql + engine: postgresql + codegen: + - plugin: py + out: db + options: + package: db + emit_sync_querier: true + emit_async_querier: true + emit_pydantic_models: true \ No newline at end of file diff --git a/internal/endtoend/testdata/exec_result/sqlc.yaml b/internal/endtoend/testdata/exec_result/sqlc.yaml index 2adbd31..e65089e 100644 --- a/internal/endtoend/testdata/exec_result/sqlc.yaml +++ b/internal/endtoend/testdata/exec_result/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/exec_rows/sqlc.yaml b/internal/endtoend/testdata/exec_rows/sqlc.yaml index 2adbd31..e65089e 100644 --- a/internal/endtoend/testdata/exec_rows/sqlc.yaml +++ b/internal/endtoend/testdata/exec_rows/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/sqlc.yaml b/internal/endtoend/testdata/inflection_exclude_table_names/sqlc.yaml index aba5400..6a37820 100644 --- a/internal/endtoend/testdata/inflection_exclude_table_names/sqlc.yaml +++ b/internal/endtoend/testdata/inflection_exclude_table_names/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/query_parameter_limit_two/sqlc.yaml b/internal/endtoend/testdata/query_parameter_limit_two/sqlc.yaml index e389988..e2a978c 100644 --- a/internal/endtoend/testdata/query_parameter_limit_two/sqlc.yaml +++ b/internal/endtoend/testdata/query_parameter_limit_two/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/query_parameter_limit_undefined/sqlc.yaml b/internal/endtoend/testdata/query_parameter_limit_undefined/sqlc.yaml index 66d7a14..45bbc03 100644 --- a/internal/endtoend/testdata/query_parameter_limit_undefined/sqlc.yaml +++ b/internal/endtoend/testdata/query_parameter_limit_undefined/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/query_parameter_limit_zero/sqlc.yaml b/internal/endtoend/testdata/query_parameter_limit_zero/sqlc.yaml index 274f730..48b4730 100644 --- a/internal/endtoend/testdata/query_parameter_limit_zero/sqlc.yaml +++ b/internal/endtoend/testdata/query_parameter_limit_zero/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/endtoend/testdata/query_parameter_no_limit/sqlc.yaml b/internal/endtoend/testdata/query_parameter_no_limit/sqlc.yaml index b563730..9d5948d 100644 --- a/internal/endtoend/testdata/query_parameter_no_limit/sqlc.yaml +++ b/internal/endtoend/testdata/query_parameter_no_limit/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: py wasm: url: file://../../../../bin/sqlc-gen-python.wasm - sha256: "a6c5d174c407007c3717eea36ff0882744346e6ba991f92f71d6ab2895204c0e" + sha256: "4950a23b591192c23b87ec6b7e0a3826e17335e35ea6cbee745703920a252164" sql: - schema: schema.sql queries: query.sql diff --git a/internal/gen.go b/internal/gen.go index f81c53b..ffe6dbf 100644 --- a/internal/gen.go +++ b/internal/gen.go @@ -222,6 +222,9 @@ func pyEnumValueName(value string) string { id := strings.Replace(value, "-", "_", -1) id = strings.Replace(id, ":", "_", -1) id = strings.Replace(id, "/", "_", -1) + id = strings.Replace(id, ">", "GT", -1) + id = strings.Replace(id, "<", "LT", -1) + id = strings.Replace(id, "=", "EQ", -1) id = pyIdentPattern.ReplaceAllString(id, "") return strings.ToUpper(id) }