Skip to content

Commit aa021ec

Browse files
committed
Added method execute_batch for Connection and Transaction
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent db462de commit aa021ec

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

docs/components/connection.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ async def main() -> None:
6161
dict_results: list[dict[str, Any]] = results.result()
6262
```
6363

64+
### Execute Batch
65+
66+
#### Parameters:
67+
68+
- `querystring`: querystrings separated by semicolons.
69+
70+
Executes a sequence of SQL statements using the simple query protocol.
71+
72+
Statements should be separated by semicolons.
73+
If an error occurs, execution of the sequence will stop at that point.
74+
This is intended for use when, for example,
75+
initializing a database schema.
76+
77+
```python
78+
async def main() -> None:
79+
...
80+
connection = await db_pool.connection()
81+
await connection.execute_batch(
82+
"CREATE TABLE psqlpy (name VARCHAR); CREATE TABLE psqlpy2 (name VARCHAR);",
83+
)
84+
```
85+
6486
### Fetch
6587

6688
#### Parameters:

docs/components/transaction.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ async def main() -> None:
144144
dict_results: list[dict[str, Any]] = results.result()
145145
```
146146

147+
### Execute Batch
148+
149+
#### Parameters:
150+
151+
- `querystring`: querystrings separated by semicolons.
152+
153+
Executes a sequence of SQL statements using the simple query protocol.
154+
155+
Statements should be separated by semicolons.
156+
If an error occurs, execution of the sequence will stop at that point.
157+
This is intended for use when, for example,
158+
initializing a database schema.
159+
160+
```python
161+
async def main() -> None:
162+
...
163+
connection = await db_pool.connection()
164+
async with connection.transaction() as transaction:
165+
await transaction.execute_batch(
166+
"CREATE TABLE psqlpy (name VARCHAR); CREATE TABLE psqlpy2 (name VARCHAR);",
167+
)
168+
```
169+
147170
### Fetch
148171

149172
#### Parameters:

0 commit comments

Comments
 (0)