Skip to content

Commit 068fd25

Browse files
committed
feat: added dataclasses tests
Signed-off-by: QuentinN42 <[email protected]>
1 parent a5d1ee8 commit 068fd25

File tree

12 files changed

+79
-0
lines changed

12 files changed

+79
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Code generated by sqlc. DO NOT EDIT.
2+
# versions:
3+
# sqlc v1.29.0
4+
import dataclasses
5+
6+
7+
@dataclasses.dataclass()
8+
class Author:
9+
id: int
10+
class_: str
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "2"
2+
plugins:
3+
- name: py
4+
wasm:
5+
url: file://../../../../bin/sqlc-gen-python.wasm
6+
sha256: "24b0da217e85c9b952a4c746476aa761e9b293a4a68bef8409d97edc1c003016"
7+
sql:
8+
- schema: schema.sql
9+
queries: query.sql
10+
engine: postgresql
11+
codegen:
12+
- plugin: py
13+
out: db
14+
options:
15+
package: db
16+
emit_sync_querier: true
17+
emit_async_querier: true
18+
emit_pydantic_models: false

internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/db/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Code generated by sqlc. DO NOT EDIT.
2+
# versions:
3+
# sqlc v1.29.0
4+
# source: query.sql
5+
from typing import Optional
6+
7+
import sqlalchemy
8+
import sqlalchemy.ext.asyncio
9+
10+
from db import models
11+
12+
13+
GET_AUTHOR = """-- name: get_author \\:one
14+
SELECT id, class FROM authors
15+
WHERE id = :p1 LIMIT 1
16+
"""
17+
18+
19+
class Querier:
20+
def __init__(self, conn: sqlalchemy.engine.Connection):
21+
self._conn = conn
22+
23+
def get_author(self, *, id: int) -> Optional[models.Author]:
24+
row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first()
25+
if row is None:
26+
return None
27+
return models.Author(
28+
id=row[0],
29+
class_=row[1],
30+
)
31+
32+
33+
class AsyncQuerier:
34+
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
35+
self._conn = conn
36+
37+
async def get_author(self, *, id: int) -> Optional[models.Author]:
38+
row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first()
39+
if row is None:
40+
return None
41+
return models.Author(
42+
id=row[0],
43+
class_=row[1],
44+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- name: GetAuthor :one
2+
SELECT * FROM authors
3+
WHERE id = $1 LIMIT 1;

0 commit comments

Comments
 (0)