|
1 | 1 | import types |
2 | 2 | from enum import Enum |
| 3 | +from io import BytesIO |
3 | 4 | from ipaddress import IPv4Address, IPv6Address |
4 | 5 | from typing import Any, Callable, List, Optional, Sequence, TypeVar, Union |
5 | 6 |
|
6 | | -from typing_extensions import Self |
| 7 | +from typing_extensions import Buffer, Self |
7 | 8 |
|
8 | 9 | _CustomClass = TypeVar( |
9 | 10 | "_CustomClass", |
@@ -809,6 +810,30 @@ class Transaction: |
809 | 810 | await cursor.close() |
810 | 811 | ``` |
811 | 812 | """ |
| 813 | + async def binary_copy_to_table( |
| 814 | + self: Self, |
| 815 | + source: Union[bytes, bytearray, Buffer, BytesIO], |
| 816 | + table_name: str, |
| 817 | + columns: Optional[Sequence[str]] = None, |
| 818 | + schema_name: Optional[str] = None, |
| 819 | + ) -> int: |
| 820 | + """Perform binary copy to PostgreSQL. |
| 821 | +
|
| 822 | + Execute `COPY table_name (<columns>) FROM STDIN (FORMAT binary)` |
| 823 | + and start sending bytes to PostgreSQL. |
| 824 | +
|
| 825 | + IMPORTANT! User is responsible for the bytes passed to the database. |
| 826 | + If bytes are incorrect user will get error from the database. |
| 827 | +
|
| 828 | + ### Parameters: |
| 829 | + - `source`: source of bytes. |
| 830 | + - `table_name`: name of the table. |
| 831 | + - `columns`: sequence of str columns. |
| 832 | + - `schema_name`: name of the schema. |
| 833 | +
|
| 834 | + ### Returns: |
| 835 | + number of inserted rows; |
| 836 | + """ |
812 | 837 |
|
813 | 838 | class Connection: |
814 | 839 | """Connection from Database Connection Pool. |
@@ -1053,6 +1078,30 @@ class Connection: |
1053 | 1078 | It necessary to commit all transactions and close all cursor |
1054 | 1079 | made by this connection. Otherwise, it won't have any practical usage. |
1055 | 1080 | """ |
| 1081 | + async def binary_copy_to_table( |
| 1082 | + self: Self, |
| 1083 | + source: Union[bytes, bytearray, Buffer, BytesIO], |
| 1084 | + table_name: str, |
| 1085 | + columns: Optional[Sequence[str]] = None, |
| 1086 | + schema_name: Optional[str] = None, |
| 1087 | + ) -> int: |
| 1088 | + """Perform binary copy to PostgreSQL. |
| 1089 | +
|
| 1090 | + Execute `COPY table_name (<columns>) FROM STDIN (FORMAT binary)` |
| 1091 | + and start sending bytes to PostgreSQL. |
| 1092 | +
|
| 1093 | + IMPORTANT! User is responsible for the bytes passed to the database. |
| 1094 | + If bytes are incorrect user will get error from the database. |
| 1095 | +
|
| 1096 | + ### Parameters: |
| 1097 | + - `source`: source of bytes. |
| 1098 | + - `table_name`: name of the table. |
| 1099 | + - `columns`: sequence of str columns. |
| 1100 | + - `schema_name`: name of the schema. |
| 1101 | +
|
| 1102 | + ### Returns: |
| 1103 | + number of inserted rows; |
| 1104 | + """ |
1056 | 1105 |
|
1057 | 1106 | class ConnectionPoolStatus: |
1058 | 1107 | max_size: int |
|
0 commit comments