src/dirbs/utils.py
def create_db_connection(db_config, readonly=False, autocommit=False):
    """Creates a DB connection to the database.

    Imports the config module, which results in the config being read from disk.
    Changes to the config file made after this method has been called will not be read.

    Calling entity should handle connection errors as appropriate.

    Arguments:
        db_config: dirbs db config object
        readonly: bool to indicate if the connect would be readonly, default False
        autocommit: bool to indicate weather the auto-commit will be on, default False (off)
    Returns:
        connection object
    """
    logger = logging.getLogger('dirbs.sql')
    logger.debug('Attempting to connect to the database {0} on host {1}'.format(db_config.database, db_config.host))
    # We hard-code 4 minutes idle keepalives, which is fairly aggressive, to avoid disconnections on VPNs, etc.
    conn = psycopg2.connect('{0} keepalives=1 keepalives_idle=240'.format(db_config.connection_string),
                            cursor_factory=LoggingNamedTupleCursor)
    conn.set_session(readonly=readonly, autocommit=autocommit)
    logger.debug('Connection to database successful.')
    return conn
Creates a DB connection to the database.

    Imports the config module, which results in the config being read from disk.
    Changes to the config file made after this method has been called will not be read.

    Calling entity should handle connection errors as appropriate.

    Arguments:
        db_config: dirbs db config object
        readonly: bool to indicate if the connect would be readonly, default False
        autocommit: bool to indicate weather the auto-commit will be on, default False (off)
    Returns:
        connection object
    
Creates a DB connection to the database.
Imports the config module, which results in the config being read from disk.
Changes to the config file made after this method has been called will not be read.

Calling entity should handle connection errors as appropriate.
Creates a DB connection to the database . Imports the config module which results in the config being read from disk . Changes to the config file made after this method has been called will not be read . Calling entity should handle connection errors as appropriate .
def create_db_connection(db_config, readonly=False, autocommit=False):
    logger = logging.getLogger('dirbs.sql')
    logger.debug('Attempting to connect to the database {0} on host {1}'.format(db_config.database, db_config.host))
    conn = psycopg2.connect('{0} keepalives=1 keepalives_idle=240'.format(db_config.connection_string),
                            cursor_factory=LoggingNamedTupleCursor)
    conn.set_session(readonly=readonly, autocommit=autocommit)
    logger.debug('Connection to database successful.')
    return conn
def create_db_connection ( db_config , readonly = False , autocommit = False ) : logger = logging . getLogger ( 'dirbs.sql' ) logger . debug ( 'Attempting to connect to the database {0} on host {1}' . format ( db_config . database , db_config . host ) ) conn = psycopg2 . connect ( '{0} keepalives=1 keepalives_idle=240' . format ( db_config . connection_string ) , cursor_factory = LoggingNamedTupleCursor ) conn . set_session ( readonly = readonly , autocommit = autocommit ) logger . debug ( 'Connection to database successful.' ) return conn
Creates a DB connection to the database.
Creates a DB connection to the database .
"""Creates a DB connection to the database.

    Imports the config module, which results in the config being read from disk.
    Changes to the config file made after this method has been called will not be read.

    Calling entity should handle connection errors as appropriate.

    Arguments:
        db_config: dirbs db config object
        readonly: bool to indicate if the connect would be readonly, default False
        autocommit: bool to indicate weather the auto-commit will be on, default False (off)
    Returns:
        connection object
    """ # We hard-code 4 minutes idle keepalives, which is fairly aggressive, to avoid disconnections on VPNs, etc.
None
db_config
dirbs db config object
dirbs db config object
readonly
bool to indicate if the connect would be readonly, default False
bool to indicate if the connect would be readonly default False
autocommit
bool to indicate weather the auto-commit will be on, default False (off)
bool to indicate weather the auto - commit will be on default False ( off )