Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enum generation if it does contain only equality-sign #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions internal/endtoend/testdata/enum_with_eq/db/models.py
Original file line number Diff line number Diff line change
@@ -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]
43 changes: 43 additions & 0 deletions internal/endtoend/testdata/enum_with_eq/db/query.py
Original file line number Diff line number Diff line change
@@ -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],
)
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/enum_with_eq/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: list :many
SELECT * FROM operations;
13 changes: 13 additions & 0 deletions internal/endtoend/testdata/enum_with_eq/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TYPE operator AS ENUM (
'=',
'>',
'<',
'>=',
'<='
);

CREATE TABLE operations (
a int,
b int,
operation operator
);
18 changes: 18 additions & 0 deletions internal/endtoend/testdata/enum_with_eq/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/exec_result/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/exec_rows/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down