Internal Class Representation

pgdbpool

pgdbpool.pool.conn_iter(connection_group)[source]

Global Connection Iterator.

pgdbpool.pool.conn_iter_locked(iterator)[source]

Global Locked Connection Iterator (wrapper).

class pgdbpool.pool.Connection[source]

Bases: object

Connection Class.

classmethod init(config)[source]

Initialize “static” Class Instance.

Parameters:

config (dict) – configuration data

classmethod _init_class()[source]

Initialize “static” Class Instance.

  • setup global config data

  • setup groups (call _setup_groups())

classmethod _setup_groups()[source]

Setup group Config / Iterator(s).

  • for each group, call _setup_connections(group_name)

classmethod _setup_connections(group)[source]

Setup Connections per group.

Parameters:

group (str) – group name

  • init DB connection for range (0, group.conn_count)

classmethod get_max_pool_size(group)[source]

Get Connection-Pool size by group name.

Parameters:

group (str) – group name

Returns:

connection count

Return type:

int

classmethod get_connection_iter_container(group)[source]

Get Connection Iterator Container by group name.

Parameters:

group (str) – group name

Returns:

connection iterator

Return type:

iterator

classmethod get_connection_container(connection)[source]

Get Connection Container by Connection.

Parameters:

connection (tuple) – (group name, group id)

Returns:

connection tuple (conn object ref, conn status)

Return type:

tuple

classmethod get_connection(connection)[source]

Alias for get_connection_container().

classmethod get_connection_count(connection)[source]

Get Connection count by Connection.

Parameters:

connection (tuple) – (group name, group id)

Returns:

connection count

Return type:

int

classmethod set_connection_status(connection, status)[source]

Set Connection status.

Parameters:
  • connection (tuple) – (group name, group id)

  • status (str) – occupied | free.

classmethod get_next_connection(group)[source]

Get Iterators next() Connection by group name.

Parameters:

group (str) – group name

Returns:

connection object

Return type:

object

classmethod connect(connection)[source]

Connect to Database.

Parameters:

connection (tuple) – (group name, group id)

classmethod reconnect(connection)[source]

Re-connect to Database.

Parameters:

connection (tuple) – (group name, group id)

class pgdbpool.pool.Query[source]

Bases: object

Query Class.

static execute_prepared(connection, sql_params)[source]

Execute a System Prepared Query.

See https://github.com/WEBcodeX1/pg_extensions/tree/main/prep_queries.

Parameters:
  • connection (tuple) – (group name, group id)

  • sql_params (str) – SQL stored procedure parameters

static execute(connection, sql_statement, sql_params=None)[source]

Execute SQL query string.

Parameters:
  • connection (tuple) – (group name, group id)

  • sql_statement (str) – SQL statement

  • sql_params (str) – SQL parameters

static check_db(connection)[source]

Check Database Connection is alive by sending simple now() request.

Parameters:

connection (tuple) – (group name, group id)

class pgdbpool.pool.Handler(group)[source]

Bases: object

(Query) Handler Class.

Example:

>>> dbpool.Connection.init(config_dict)
>>>
>>> sql = 'select * from table1'
>>>
>>> with dbpool.Handler('group1') as db:
>>>     for rec in db.query(sql):
>>>         print(str(rec))
__init__(group)[source]

Initialize Handler.

Parameters:

group (str) – group name

__enter__()[source]

Overloaded __enter__.

__exit__(exc_type, exc_val, exc_tb)[source]

Overloaded __exit__.

Call _cleanup() on exit.

query(statement, params=None)[source]

Query Wrapper Class.

query_prepared(params)[source]

Query Prepared Wrapper Class.

_cleanup()[source]

Cleanup Connection (exit with block).

  • Try to commit() on no autocommit if still unfinished transaction(s)

  • Set connection status to ‘free’