Skip to content

Commit 876438a

Browse files
authored
Fix missing empty lines when using asyncpg (#41)
* refactor: fix missing empty lines in asyncpg.go, sqlc.yaml, queries.py (#42) * fragment
1 parent 0b8a9cb commit 876438a

4 files changed

Lines changed: 49 additions & 44 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixed
2+
body: Fixed missing empty lines when using `asyncpg` driver.
3+
time: 2025-05-06T00:16:07.0299503+02:00
4+
custom:
5+
Author: rayakame
6+
PR: "41"

internal/codegen/drivers/asyncpg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func AsyncpgBuildPyQueryFunc(query *core.Query, body *builders.IndentStringBuild
9191
}
9292
}
9393
body.WriteLine("))")
94-
body.WriteIndentedString(indentLevel+1, "return return_rows")
94+
body.WriteIndentedLine(indentLevel+1, "return return_rows")
9595
} else {
9696
body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("return_rows.append(%s(row[0]))", retType))
97-
body.WriteIndentedString(indentLevel+1, "return return_rows")
97+
body.WriteIndentedLine(indentLevel+1, "return return_rows")
9898
}
9999
}
100100
return nil

sqlc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- name: python
44
wasm:
55
url: file://sqlc-gen-better-python.wasm
6-
sha256: beb883283e1e6fbe0f807a5294c4418f7674aa3cb23c89b28807fa8cd78c58ee
6+
sha256: e5f90e5f52b4847a35d9c60a2828134bcd2a89f798793899fed7a0738aefed1a
77
sql:
88
- schema: test/schema.sql
99
queries: test/queries.sql
@@ -15,7 +15,7 @@ sql:
1515
package: test
1616
sql_driver: asyncpg
1717
model_type: msgspec
18-
emit_classes: false
18+
emit_classes: true
1919
omit_unused_models: true
2020
emit_init_file: true
2121

test/queries.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
__all__: typing.Sequence[str] = (
88
"GetStudentAndScoreRow",
99
"GetStudentAndScoresRow",
10-
"delete_author",
11-
"get_student_and_score",
12-
"get_student_and_scores",
13-
"list_authors",
14-
"list_authors2",
15-
"update_author",
10+
"Queries",
1611
)
1712

1813
import msgspec
@@ -74,37 +69,41 @@ class GetStudentAndScoresRow(msgspec.Struct):
7469
"""
7570

7671

77-
async def delete_author(conn: asyncpg.Connection, *, id: int) -> None:
78-
await conn.execute(DELETE_AUTHOR, id)
79-
80-
81-
async def get_student_and_score(conn: asyncpg.Connection, *, id: int) -> typing.Optional[GetStudentAndScoreRow]:
82-
row = await conn.fetchrow(GET_STUDENT_AND_SCORE, id)
83-
if row is None:
84-
return None
85-
return GetStudentAndScoreRow(student=models.Student(id=row[0], name=row[1], age=row[2]), test_score=models.TestScore(student_id=row[3], score=row[4], grade=row[5]))
86-
87-
88-
async def get_student_and_scores(conn: asyncpg.Connection) -> typing.Sequence[GetStudentAndScoresRow]:
89-
rows = await conn.fetch(GET_STUDENT_AND_SCORES)
90-
return_rows: typing.List[GetStudentAndScoresRow] = []
91-
for row in rows:
92-
return_rows.append(GetStudentAndScoresRow(student=models.Student(id=row[0], name=row[1], age=row[2]), test_score=models.TestScore(student_id=row[3], score=row[4], grade=row[5])))
93-
return return_rows
94-
95-
async def list_authors(conn: asyncpg.Connection, *, ids: typing.Sequence[int]) -> typing.Sequence[int]:
96-
rows = await conn.fetch(LIST_AUTHORS, ids)
97-
return_rows: typing.List[int] = []
98-
for row in rows:
99-
return_rows.append(int(row[0]))
100-
return return_rows
101-
102-
async def list_authors2(conn: asyncpg.Connection, *, id: int) -> typing.Sequence[int]:
103-
rows = await conn.fetch(LIST_AUTHORS2, id)
104-
return_rows: typing.List[int] = []
105-
for row in rows:
106-
return_rows.append(int(row[0]))
107-
return return_rows
108-
109-
async def update_author(conn: asyncpg.Connection, *, name: str, bio: str, id: int) -> None:
110-
await conn.execute(UPDATE_AUTHOR, name, bio, id)
72+
class Queries:
73+
__slots__ = ("_conn",)
74+
75+
def __init__(self, conn: asyncpg.Connection):
76+
self._conn = conn
77+
78+
async def delete_author(self, *, id: int) -> None:
79+
await self._conn.execute(DELETE_AUTHOR, id)
80+
81+
async def get_student_and_score(self, *, id: int) -> typing.Optional[GetStudentAndScoreRow]:
82+
row = await self._conn.fetchrow(GET_STUDENT_AND_SCORE, id)
83+
if row is None:
84+
return None
85+
return GetStudentAndScoreRow(student=models.Student(id=row[0], name=row[1], age=row[2]), test_score=models.TestScore(student_id=row[3], score=row[4], grade=row[5]))
86+
87+
async def get_student_and_scores(self) -> typing.Sequence[GetStudentAndScoresRow]:
88+
rows = await self._conn.fetch(GET_STUDENT_AND_SCORES)
89+
return_rows: typing.List[GetStudentAndScoresRow] = []
90+
for row in rows:
91+
return_rows.append(GetStudentAndScoresRow(student=models.Student(id=row[0], name=row[1], age=row[2]), test_score=models.TestScore(student_id=row[3], score=row[4], grade=row[5])))
92+
return return_rows
93+
94+
async def list_authors(self, *, ids: typing.Sequence[int]) -> typing.Sequence[int]:
95+
rows = await self._conn.fetch(LIST_AUTHORS, ids)
96+
return_rows: typing.List[int] = []
97+
for row in rows:
98+
return_rows.append(int(row[0]))
99+
return return_rows
100+
101+
async def list_authors2(self, *, id: int) -> typing.Sequence[int]:
102+
rows = await self._conn.fetch(LIST_AUTHORS2, id)
103+
return_rows: typing.List[int] = []
104+
for row in rows:
105+
return_rows.append(int(row[0]))
106+
return return_rows
107+
108+
async def update_author(self, *, name: str, bio: str, id: int) -> None:
109+
await self._conn.execute(UPDATE_AUTHOR, name, bio, id)

0 commit comments

Comments
 (0)