gws.base.database.provider

Source code: gws.base.database.provider

Module Contents

class gws.base.database.provider.Config(*args, **kwargs)

Bases: gws.Config

Database provider

pool: dict | None

Options for connection pooling.

schemaCacheLifeTime: gws.Duration = '3600'

Life time for schema caches.

withPool: bool | None = False

Use connection pooling

class gws.base.database.provider.Object

Bases: gws.DatabaseProvider

Database Provider.

A database Provider wraps SQLAlchemy Engine and Connection objects and provides common db functionality.

SA_TO_ATTR
SA_TO_GEOM
saEngine: gws.lib.sa.Engine
saMetaMap: dict[str, gws.lib.sa.MetaData]
UNKNOWN_ARRAY_TYPE
UNKNOWN_TYPE
activate()

Activation hook.

column(table, column_name)

SQLAlchemy Column object for a specific column.

configure()

Configuration hook.

connect()

Context manager for SQLAlchemy Connection.

Context calls to this method can be nested. An inner call is a no-op, as no new connection is created. Only the outermost connection is closed upon exit:

with db.connect():
    ...
    with db.connect():  # no-op
        ...
    # connection remains open
    ...
# connection closed
count(table)

Return table record count or 0 if the table does not exist.

create_engine(**kwargs)

CreateSQLAlchemy Engine object for this provider.

describe(table)

Describe a table.

describe_column(table, column_name) gws.ColumnDescription
engine()

Get SQLAlchemy Engine object for this provider.

engine_options(**kwargs)

Add defaults to the SA engine options.

execute_text(sql, **kwargs)

Execute a textual DML stmt and return a result.

has_column(table, column_name)

Check if a specific column exists.

has_table(table_name: str)

Check if a specific table exists.

reflect_schema(schema: str)
select_text(sql, **kwargs)

Execute a textual SELECT stmt and return a list of record dicts.

table(table, **kwargs)

SQLAlchemy Table object for a specific table.