turu.postgres¶
turu.postgres.Connection
¶
Source code in turu-postgres/src/turu/postgres/connection.py
close()
¶
commit()
¶
connect(conninfo='', *, autocommit=False, row_factory=None, prepare_threshold=5, cursor_factory=None, context=None, **kwargs)
classmethod
¶
Connect to a database.
Source code in turu-postgres/src/turu/postgres/connection.py
connect_from_env(*, dbname_envname='POSTGRES_DB', user_envname='POSTGRES_USER', password_envname='POSTGRES_PASSWORD', host_envname='POSTGRES_HOST', port_envname='POSTGRES_PORT', autocommit=False, row_factory=None, prepare_threshold=5, cursor_factory=None, context=None, **kwargs)
classmethod
¶
Connect to a database using environment variables.
Source code in turu-postgres/src/turu/postgres/connection.py
cursor()
¶
rollback()
¶
turu.postgres.Cursor
¶
Source code in turu-postgres/src/turu/postgres/cursor.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
arraysize: int
property
writable
¶
The number of rows to fetch at a time with .fetchmany()
.
It defaults to 1 meaning to fetch a single row at a time.
rowcount: int
property
¶
The number of rows that the last .execute*()
produced (for DQL statements like )
or affected (for DML statements like or ).
The attribute is -1
in case no .execute*()
has been performed
on the cursor or the rowcount of the last operation is cannot be determined by the interface.
execute(operation, parameters=None)
¶
Prepare and execute a database operation (query or command).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation
|
str
|
A database operation (query or command). |
required |
parameters
|
Optional[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/cursor.py
execute_map(row_type, operation, parameters=None)
¶
Execute a database operation (query or command) and map each row to a row_type
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_type
|
Type[GenericNewRowType]
|
The type of the row that will be returned. |
required |
operation
|
str
|
A database operation (query or command). |
required |
parameters
|
Optional[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
None
|
Returns:
Type | Description |
---|---|
Cursor[GenericNewRowType, Parameters]
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/cursor.py
execute_with_tag(tag, operation, parameters=None)
¶
Execute a database operation (Insert, Update, Delete) with a tag.
This is not defined in PEP 249,
This method is provided for testing,
and is intended to be used in conjunction with MockConnection.inject_operation_with_tag
.
executemany(operation, seq_of_parameters)
¶
Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation
|
str
|
A database operation (query or command). |
required |
seq_of_parameters
|
Sequence[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
required |
Returns:
Type | Description |
---|---|
Self
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/cursor.py
executemany_map(row_type, operation, seq_of_parameters)
¶
Execute a database operation (query or command) against all parameter sequences or mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_type
|
Type[GenericNewRowType]
|
The type of the row that will be returned. |
required |
operation
|
str
|
A database operation (query or command). |
required |
seq_of_parameters
|
Sequence[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
required |
Returns:
Type | Description |
---|---|
Cursor[GenericNewRowType, Parameters]
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/cursor.py
executemany_with_tag(tag, operation, seq_of_parameters)
¶
Execute a database operation (Insert, Update, Delete) against all parameter sequences or mappings with a tag.
This is not defined in PEP 249,
This method is provided for testing,
and is intended to be used in conjunction with MockConnection.inject_operation_with_tag
.
Source code in turu-postgres/src/turu/postgres/cursor.py
fetchall()
¶
fetchmany(size=None)
¶
Fetch the next set of rows of a query result.
An empty sequence is returned when no more rows are available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
Optional[int]
|
The number of rows to fetch per call.
If this parameter is not used, it is usually refer to use the |
None
|
Source code in turu-postgres/src/turu/postgres/cursor.py
fetchone()
¶
Fetch the next row of a query result set.
Source code in turu-postgres/src/turu/postgres/cursor.py
turu.postgres.AsyncConnection
¶
Source code in turu-postgres/src/turu/postgres/async_connection.py
close()
async
¶
commit()
async
¶
connect(conninfo='', *, autocommit=False, row_factory=None, prepare_threshold=5, cursor_factory=None, context=None, **kwargs)
async
classmethod
¶
Connect to a database.
Source code in turu-postgres/src/turu/postgres/async_connection.py
connect_from_env(*, autocommit=False, row_factory=None, prepare_threshold=5, cursor_factory=None, context=None, dbname_envname='POSTGRES_DB', user_envname='POSTGRES_USER', password_envname='POSTGRES_PASSWORD', host_envname='POSTGRES_HOST', port_envname='POSTGRES_PORT', **kwargs)
async
classmethod
¶
Connect to a database using environment variables.
Source code in turu-postgres/src/turu/postgres/async_connection.py
cursor()
async
¶
rollback()
async
¶
Roll back to the start of any pending transaction.
Closing a connection without committing the changes first will cause an implicit rollback to be performed.
turu.postgres.AsyncCursor
¶
Source code in turu-postgres/src/turu/postgres/async_cursor.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
arraysize: int
property
writable
¶
This read/write attribute specifies the number of rows to fetch at a time with .fetchmany()
.
It defaults to 1 meaning to fetch a single row at a time.
Implementations must observe this value with respect to the .fetchmany()
method,
but are free to interact with the database a single row at a time.
It may also be used in the implementation of .executemany()
.
rowcount: int
property
¶
the number of rows that the last .execute*() produced (for DQL statements like ) or affected (for DML statements like or ).
The attribute is -1 in case no .execute*() has been performed on the cursor or the rowcount of the last operation is cannot be determined by the interface.
execute(operation, parameters=None)
async
¶
Prepare and execute a database operation (query or command).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation
|
str
|
A database operation (query or command). |
required |
parameters
|
Optional[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/async_cursor.py
execute_map(row_type, operation, parameters=None)
async
¶
Execute a database operation (query or command) and map each row to a row_type
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_type
|
Type[GenericNewRowType]
|
The type of the row that will be returned. |
required |
operation
|
str
|
A database operation (query or command). |
required |
parameters
|
Optional[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
None
|
Returns:
Type | Description |
---|---|
AsyncCursor[GenericNewRowType, Parameters]
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/async_cursor.py
execute_with_tag(tag, operation, parameters=None)
async
¶
Execute a database operation (Insert, Update, Delete) with a tag.
This is not defined in PEP 249,
This method executes an operation (Insert, Update, Delete) that does not return a value with a tag. This tag is used to verify that the specified operation is executed in order when testing with Mock.
Source code in turu-postgres/src/turu/postgres/async_cursor.py
executemany(operation, seq_of_parameters)
async
¶
Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation
|
str
|
A database operation (query or command). |
required |
seq_of_parameters
|
Sequence[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
required |
Returns:
Type | Description |
---|---|
Self
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/async_cursor.py
executemany_map(row_type, operation, seq_of_parameters)
async
¶
Execute a database operation (query or command) against all parameter sequences or mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_type
|
Type[GenericNewRowType]
|
The type of the row that will be returned. |
required |
operation
|
str
|
A database operation (query or command). |
required |
seq_of_parameters
|
Sequence[Parameters]
|
Parameters may be provided as sequence or mapping and will be bound to variables in the operation. |
required |
Returns:
Type | Description |
---|---|
AsyncCursor[GenericNewRowType, Parameters]
|
A cursor that holds a reference to an operation. |
Source code in turu-postgres/src/turu/postgres/async_cursor.py
executemany_with_tag(tag, operation, seq_of_parameters)
async
¶
Execute a database operation (Insert, Update, Delete) against all parameter sequences or mappings with a tag.
This is not defined in PEP 249,
This method executes an operation (Insert, Update, Delete) that does not return a value with a tag. This tag is used to verify that the specified operation is executed in order when testing with Mock.
Source code in turu-postgres/src/turu/postgres/async_cursor.py
fetchall()
async
¶
fetchmany(size=None)
async
¶
Fetch the next set of rows of a query result.
An empty sequence is returned when no more rows are available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
Optional[int]
|
The number of rows to fetch per call.
If this parameter is not used, it is usually refer to use the |
None
|
Source code in turu-postgres/src/turu/postgres/async_cursor.py
fetchone()
async
¶
Fetch the next row of a query result set.