Skip to content

flowmachine.core.connection

Source: flowmachine/core/connection.py

Class(es) representing our connection to the database, along with utilities regarding the database.

Class Connection

Connection(*, port: Union[int, NoneType] = None, user: Union[str, NoneType] = None, password: Union[str, NoneType] = None, host: Union[str, NoneType] = None, database: Union[str, NoneType] = None, pool_size: int = 5, overflow: int = 10, conn_str: Union[str, NoneType] = None) -> None
Source: flowmachine/core/connection.py

Establishes a connection with the database and provide methods for fetching data.

Attributes

Parameters

  • port: typing.Union[int, NoneType], default None

  • user, password, host, database, conn_str: str

    Connection info for the database, as used by sqlalchemy. Provide either port, user, password, host and database or conn_str.

  • pool_size: int, default 5

    Number of connections to the db to use

  • overflow: int, default 10

    Number of connections to the db to open temporarily

Note

sqlalchemy will open at most pool_size+overflow connections to the db and requests for more will time out rapidly. sqlalchemy will not immediately open pool_size connections, but will always keep that many open once they have been. You will, ordinarily be OK to ignore this setting.

Methods

close

close(self)
Source: flowmachine/core/connection.py

Close the connection

fetch

fetch(self, query: str)
Source: flowmachine/core/connection.py

Parameters
  • query: str

    SQL query string.

  • Fetches a query from the database and return as a list of lists

has_table

has_table(self, name: str, schema: Union[str, NoneType] = None) -> bool
Source: flowmachine/core/connection.py

Check if a table exists in the database.

Parameters
  • name: str

    Name of the table

  • schema: typing.Union[str, NoneType], default None

    Check only this schema, if none look for the table in any schema

Returns
  • bool

    true if the given table exists, otherwise false.

max_date

max_date(self, table: str = 'calls') -> datetime.date
Source: flowmachine/core/connection.py

Finds the maximum date in the given events table.

Parameters
  • table: str, default calls

    The table to check

Returns
  • datetime.date

min_date

min_date(self, table: str = 'calls') -> datetime.date
Source: flowmachine/core/connection.py

Finds the minimum date in the given events table.

Parameters
  • table: str, default calls

    The table to check

Returns
  • datetime.date

available_dates

available_dates
Source: flowmachine/core/connection.py

Returns
  • typing.Dict[str, typing.List[datetime.date]]

    Dict with tables as keys, containing lists of dates which are present

available_tables

available_tables
Source: flowmachine/core/connection.py

location_table

location_table
Source: flowmachine/core/connection.py

Get the name of the table referenced by the location_id field of the events tables.

Returns
  • str

    The fully qualified name of the table location_id references

location_tables

location_tables
Source: flowmachine/core/connection.py

subscriber_tables

subscriber_tables
Source: flowmachine/core/connection.py