Skip to content

Commit 427171d

Browse files
committed
Add support for :copyfrom with shuffled parameter ordering and update examples
1 parent bf98574 commit 427171d

File tree

30 files changed

+85
-36
lines changed

30 files changed

+85
-36
lines changed

internal/endtoend/testdata/copyfrom/python/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55
import datetime
66
from typing import Optional

internal/endtoend/testdata/copyfrom/python/query.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query.sql
55
import dataclasses
66
from typing import Any, List, Optional
@@ -36,6 +36,20 @@
3636
"""
3737

3838

39+
CREATE_USERS_SHUFFLED = """-- name: create_users_shuffled \\:copyfrom
40+
INSERT INTO users (email, name, bio, age, active) VALUES (:p2, :p1, :p3, :p4, :p5)
41+
"""
42+
43+
44+
@dataclasses.dataclass()
45+
class CreateUsersShuffledParams:
46+
name: str
47+
email: str
48+
bio: Optional[str]
49+
age: Optional[int]
50+
active: Optional[bool]
51+
52+
3953
CREATE_USERS_WITH_DETAILS = """-- name: create_users_with_details \\:copyfrom
4054
INSERT INTO users (email, name, bio, age, active) VALUES (:p1, :p2, :p3, :p4, :p5)
4155
"""
@@ -90,6 +104,19 @@ def create_users_batch(self, arg_list: List[Any]) -> int:
90104
result = self._conn.execute(sqlalchemy.text(CREATE_USERS_BATCH), arg_list)
91105
return result.rowcount
92106

107+
def create_users_shuffled(self, arg_list: List[CreateUsersShuffledParams]) -> int:
108+
data = list()
109+
for item in arg_list:
110+
data.append({
111+
"p1": item.name,
112+
"p2": item.email,
113+
"p3": item.bio,
114+
"p4": item.age,
115+
"p5": item.active,
116+
})
117+
result = self._conn.execute(sqlalchemy.text(CREATE_USERS_SHUFFLED), data)
118+
return result.rowcount
119+
93120
def create_users_with_details(self, arg_list: List[CreateUsersWithDetailsParams]) -> int:
94121
data = list()
95122
for item in arg_list:
@@ -144,6 +171,19 @@ async def create_users_batch(self, arg_list: List[Any]) -> int:
144171
result = await self._conn.execute(sqlalchemy.text(CREATE_USERS_BATCH), arg_list)
145172
return result.rowcount
146173

174+
async def create_users_shuffled(self, arg_list: List[CreateUsersShuffledParams]) -> int:
175+
data = list()
176+
for item in arg_list:
177+
data.append({
178+
"p1": item.name,
179+
"p2": item.email,
180+
"p3": item.bio,
181+
"p4": item.age,
182+
"p5": item.active,
183+
})
184+
result = await self._conn.execute(sqlalchemy.text(CREATE_USERS_SHUFFLED), data)
185+
return result.rowcount
186+
147187
async def create_users_with_details(self, arg_list: List[CreateUsersWithDetailsParams]) -> int:
148188
data = list()
149189
for item in arg_list:

internal/endtoend/testdata/copyfrom/query.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ INSERT INTO users (email, name) VALUES (@email, @name) RETURNING *;
1414
INSERT INTO users (email, name) VALUES (@email, @name);
1515

1616
-- name: CreateUsersWithDetails :copyfrom
17-
INSERT INTO users (email, name, bio, age, active) VALUES ($1, $2, $3, $4, $5);
17+
INSERT INTO users (email, name, bio, age, active) VALUES ($1, $2, $3, $4, $5);
18+
19+
-- name: CreateUsersShuffled :copyfrom
20+
INSERT INTO users (email, name, bio, age, active) VALUES ($2, $1, $3, $4, $5);

internal/endtoend/testdata/copyfrom/sqlc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- name: py
44
wasm:
55
url: file://../../../../bin/sqlc-gen-python.wasm
6-
sha256: "36baa58bf107df9d93c7fcd9191bf431b9da6bbce754e9ef2d6da3439dbf8a7c"
6+
sha256: "d587b6af0bfe07dbb2c316bffb5f7f5d0073a60788c5d533b84373067c9c1916"
77
sql:
88
- schema: "schema.sql"
99
queries: "query.sql"

internal/endtoend/testdata/emit_pydantic_models/db/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import pydantic
55
from typing import Optional
66

internal/endtoend/testdata/emit_pydantic_models/db/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query.sql
55
from typing import AsyncIterator, Iterator, Optional
66

internal/endtoend/testdata/emit_pydantic_models/sqlc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- name: py
44
wasm:
55
url: file://../../../../bin/sqlc-gen-python.wasm
6-
sha256: "36baa58bf107df9d93c7fcd9191bf431b9da6bbce754e9ef2d6da3439dbf8a7c"
6+
sha256: "d587b6af0bfe07dbb2c316bffb5f7f5d0073a60788c5d533b84373067c9c1916"
77
sql:
88
- schema: schema.sql
99
queries: query.sql

internal/endtoend/testdata/emit_str_enum/db/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
import dataclasses
55
import enum
66
from typing import Optional

internal/endtoend/testdata/emit_str_enum/db/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.29.0
3+
# sqlc v1.30.0
44
# source: query.sql
55
from typing import AsyncIterator, Iterator, Optional
66

internal/endtoend/testdata/emit_str_enum/sqlc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- name: py
44
wasm:
55
url: file://../../../../bin/sqlc-gen-python.wasm
6-
sha256: "36baa58bf107df9d93c7fcd9191bf431b9da6bbce754e9ef2d6da3439dbf8a7c"
6+
sha256: "d587b6af0bfe07dbb2c316bffb5f7f5d0073a60788c5d533b84373067c9c1916"
77
sql:
88
- schema: schema.sql
99
queries: query.sql

0 commit comments

Comments
 (0)