Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dswistowski wants to merge1 commit intosqlc-dev:main
base:main
Choose a base branch
Loading
fromdswistowski:main
Open
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Empty file.
20 changes: 20 additions & 0 deletionsinternal/endtoend/testdata/enum_with_eq/db/models.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsinternal/endtoend/testdata/enum_with_eq/db/query.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsinternal/endtoend/testdata/enum_with_eq/query.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
-- name: list :many
SELECT * FROM operations;
13 changes: 13 additions & 0 deletionsinternal/endtoend/testdata/enum_with_eq/schema.sql
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsinternal/endtoend/testdata/enum_with_eq/sqlc.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletioninternal/endtoend/testdata/exec_result/sqlc.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletioninternal/endtoend/testdata/exec_rows/sqlc.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsinternal/gen.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp