File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44"""
55Manage complex COPY operations; one-to-many COPY streaming.
66
7- Primarily this module houses the `CopyManager` class.
8-
9- >>> import postgresql
10- >>> src = postgresql.open(...)
11- >>> dst = postgresql.open(...)
12- >>> from postgresql.copyman import COPY
13- >>>
14- >>> COPY(src.prepare("COPY"), dst.prepare("COPY"))
7+ Primarily this module houses the `CopyManager` class, and the `transfer`
8+ function for a high-level interface to using the `CopyManager`.
159"""
1610import sys
1711from abc import abstractmethod , abstractproperty
@@ -815,17 +809,16 @@ def __next__(self):
815809 self ._stats = (0 , 0 )
816810 return current_stats
817811
818- def COPY (producer , * receivers , progress = None ):
812+ def transfer (producer , * receivers ):
813+ """
814+ Perform a COPY operation using the given statements::
815+
816+ >>> import copyman
817+ >>> copyman.transfer(src.prepare("COPY table TO STDOUT"), dst.prepare("COPY table FROM STDIN"))
818+ """
819819 cm = CopyManager (
820820 StatementProducer (producer ),
821821 * [x if isinstance (x , Receiver ) else StatementReceiver (x ) for x in receivers ]
822822 )
823- try :
824- if progress :
825- pass
826- else :
827- cm .run ()
828- except Fault as e :
829- typ , val , tb = next (iter (e .faults .values ()))
830- raise val
823+ cm .run ()
831824 return (cm .producer .total_messages , cm .producer .total_bytes )
Original file line number Diff line number Diff line change @@ -16,13 +16,13 @@ be used when transferring COPY data to and from arbitrary Python
1616interfaces.
1717
1818Direct connection-to-connection COPY operations can be performed using the
19- high-level `postgresql.copyman.COPY ` function::
19+ high-level `postgresql.copyman.transfer ` function::
2020
21- >>> from postgresql.copyman import COPY
21+ >>> from postgresql import copyman
2222 >>> send_stmt = source.prepare("COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT")
2323 >>> destination.execute("CREATE TEMP TABLE loading_table (i int8)")
2424 >>> receive_stmt = destination.prepare("COPY loading_table FROM STDIN")
25- >>> total_rows, total_bytes = COPY (send_stmt, receive_stmt)
25+ >>> total_rows, total_bytes = copyman.transfer (send_stmt, receive_stmt)
2626
2727However, if more control is needed, the `postgresql.copyman.CopyManager` class
2828should be used directly.
Original file line number Diff line number Diff line change @@ -360,7 +360,7 @@ def testEmptyRows(self):
360360 def testCopyOne (self ):
361361 from io import BytesIO
362362 b = BytesIO ()
363- copyman .COPY (
363+ copyman .transfer (
364364 prepare ('COPY (SELECT 1) TO STDOUT' ),
365365 copyman .CallReceiver (b .writelines )
366366 )
@@ -371,7 +371,7 @@ def testCopyOne(self):
371371 def testCopyNone (self ):
372372 from io import BytesIO
373373 b = BytesIO ()
374- copyman .COPY (
374+ copyman .transfer (
375375 prepare ('COPY (SELECT 1 LIMIT 0) TO STDOUT' ),
376376 copyman .CallReceiver (b .writelines )
377377 )
You can’t perform that action at this time.
0 commit comments