gws.base.database.connection¶
Database connection wrapper.
Source code: gws.base.database.connection
Module Contents¶
- class gws.base.database.connection.Object(db: gws.DatabaseProvider, conn: gws.lib.sa.Connection)¶
Bases:
gws.DatabaseConnectionDatabase connection.
- db: gws.DatabaseProvider¶
Provider this connection belongs to.
- saConn: gws.lib.sa.Connection¶
The underlying SQLAlchemy connection.
- execute(stmt, params=None, execution_options=None)¶
Execute a statement.
- Parameters:
stmt – Statement or SQL string.
params – Bind parameters, a dict or a list of dicts.
execution_options – SQLAlchemy execution options.
- Returns:
The result.
- fetch_all(stmt, **params)¶
Execute a statement and return all rows.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
A list of rows as dicts.
- fetch_first(stmt, **params)¶
Execute a statement and return the first row.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
The first row as a dict, or
Noneif there are no rows.
- fetch_int(stmt, **params)¶
Execute a statement and return the first column of the first row as an integer.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
The integer, or
Noneif there are no rows or the value isNULL.- Raises:
ValueError – If the value is not an integer.
- fetch_ints(stmt, **params)¶
Execute a statement and return the first column of all rows as integers.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
A list of integers.
- Raises:
ValueError – If a value is not an integer.
- fetch_scalar(stmt, **params)¶
Execute a statement and return the first column of the first row.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
The value, or
Noneif there are no rows.
- fetch_scalars(stmt, **params)¶
Execute a statement and return the first column of all rows.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
A list of values.
- fetch_string(stmt, **params)¶
Execute a statement and return the first column of the first row as a string.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
The string, or
Noneif there are no rows or the value isNULL.
- fetch_strings(stmt, **params)¶
Execute a statement and return the first column of all rows as strings.
- Parameters:
stmt – Statement or SQL string.
**params – Bind parameters.
- Returns:
A list of strings, with
NULLvalues as empty strings.