Package gavo :: Package base :: Module sqlsupport :: Class GAVOConnection
[frames] | no frames]

Class GAVOConnection

source code

                    object --+    
                             |    
psycopg2.extensions.connection --+
                                 |
                                GAVOConnection
Known Subclasses:

A psycopg2 connection with some additional methods.

This derivation is also done so we can attach the getDBConnection arguments to the connection; it is used when recovering from a database restart.

Instance Methods
 
setTimeout(self, timeout)
sets a timeout on queries.
source code
 
getTimeout(self)
returns the current timeout setting.
source code
 
timeoutSet(*args, **kwds)
a contextmanager to have a timeout set in the controlled section.
source code
 
queryToDicts(self, query, args={}, timeout=None, caseFixer=None)
iterates over dictionary rows for query.
source code
 
query(self, query, args={}, timeout=None)
iterates over result tuples for query.
source code
 
execute(self, query, args={})
executes query in a cursor.
source code
 
savepoint(*args, **kwds)
sets up a section protected by a savepoint that will be released after use.
source code

Inherited from psycopg2.extensions.connection: __enter__, __exit__, __init__, __new__, __repr__, __str__, cancel, close, commit, cursor, fileno, get_backend_pid, get_parameter_status, get_transaction_status, isexecuting, lobject, poll, reset, rollback, set_client_encoding, set_isolation_level, set_session, tpc_begin, tpc_commit, tpc_prepare, tpc_recover, tpc_rollback, xid

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties

Inherited from psycopg2.extensions.connection: DataError, DatabaseError, Error, IntegrityError, InterfaceError, InternalError, NotSupportedError, OperationalError, ProgrammingError, Warning, async, autocommit, binary_types, closed, cursor_factory, dsn, encoding, isolation_level, notices, notifies, protocol_version, server_version, status, string_types

Inherited from object: __class__

Method Details

setTimeout(self, timeout)

source code 

sets a timeout on queries.

timeout is in seconds; timeout=0 disables timeouts (this is what postgres does, too)

getTimeout(self)

source code 

returns the current timeout setting.

The value is in float seconds.

timeoutSet(*args, **kwds)

source code 

a contextmanager to have a timeout set in the controlled section.

Decorators:
  • @contextlib.contextmanager

queryToDicts(self, query, args={}, timeout=None, caseFixer=None)

source code 

iterates over dictionary rows for query.

This is mainly for ad-hoc queries needing little metadata.

The dictionary keys are determined by what the database says the column titles are; thus, it's usually lower-cased variants of what's in the select-list. To fix this, you can pass in a caseFixer dict that gives a properly cased version of lowercase names.

execute(self, query, args={})

source code 

executes query in a cursor.

This returns the rowcount of the cursor used.

savepoint(*args, **kwds)

source code 

sets up a section protected by a savepoint that will be released after use.

If an exception happens in the controlled section, the connection will be rolled back to the savepoint.

Decorators:
  • @contextlib.contextmanager