Skip to content

Commit 2ff13ad

Browse files
committed
Add support for :copyfrom via executemany()
1 parent 53fa0b2 commit 2ff13ad

File tree

44 files changed

+435
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+435
-45
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ bin
55
.direnv
66
.devenv*
77
devenv.local.nix
8+
9+
.idea/

examples/src/authors/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.28.0
3+
# sqlc v1.29.0
44
import dataclasses
55
from typing import Optional
66

examples/src/authors/query.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
3+
# sqlc v1.29.0
44
# source: query.sql
5-
from typing import AsyncIterator, Iterator, Optional
5+
from typing import Any, AsyncIterator, Iterator, List, Optional
66

77
import sqlalchemy
88
import sqlalchemy.ext.asyncio
@@ -20,6 +20,11 @@
2020
"""
2121

2222

23+
CREATE_AUTHORS_BATCH = """-- name: create_authors_batch \\:copyfrom
24+
INSERT INTO authors (name, bio) VALUES (:p1, :p2)
25+
"""
26+
27+
2328
DELETE_AUTHOR = """-- name: delete_author \\:exec
2429
DELETE FROM authors
2530
WHERE id = :p1
@@ -52,6 +57,10 @@ def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Aut
5257
bio=row[2],
5358
)
5459

60+
def create_authors_batch(self, arg_list: List[Any]) -> int:
61+
result = self._conn.executemany(sqlalchemy.text(CREATE_AUTHORS_BATCH), arg_list)
62+
return result.rowcount
63+
5564
def delete_author(self, *, id: int) -> None:
5665
self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})
5766

@@ -89,6 +98,10 @@ async def create_author(self, *, name: str, bio: Optional[str]) -> Optional[mode
8998
bio=row[2],
9099
)
91100

101+
async def create_authors_batch(self, arg_list: List[Any]) -> int:
102+
result = await self._conn.executemany(sqlalchemy.text(CREATE_AUTHORS_BATCH), arg_list)
103+
return result.rowcount
104+
92105
async def delete_author(self, *, id: int) -> None:
93106
await self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})
94107

examples/src/authors/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ RETURNING *;
1717
-- name: DeleteAuthor :exec
1818
DELETE FROM authors
1919
WHERE id = $1;
20+
21+
-- name: CreateAuthorsBatch :copyfrom
22+
INSERT INTO authors (name, bio) VALUES ($1, $2);

examples/src/booktest/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.28.0
3+
# sqlc v1.29.0
44
import dataclasses
55
import datetime
66
import enum

examples/src/booktest/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.28.0
3+
# sqlc v1.29.0
44
# source: query.sql
55
import dataclasses
66
import datetime

examples/src/jets/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.28.0
3+
# sqlc v1.29.0
44
import dataclasses
55

66

examples/src/jets/query-building.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.28.0
3+
# sqlc v1.29.0
44
# source: query-building.sql
55
from typing import AsyncIterator, Optional
66

examples/src/ondeck/city.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.28.0
3+
# sqlc v1.29.0
44
# source: city.sql
55
from typing import AsyncIterator, Optional
66

examples/src/ondeck/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.28.0
3+
# sqlc v1.29.0
44
import dataclasses
55
import datetime
66
import enum

0 commit comments

Comments
 (0)