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: Optional[int] = None, user: Optional[str] = None, password: Optional[str] = None, host: Optional[str] = None, database: Optional[str] = None, pool_size: int = 5, overflow: int = 10, conn_str: Optional[str] = None) -> None
Establishes a connection with the database and provide methods for fetching data.
Attributes¶
Parameters¶
-
port
:typing.Optional
, defaultNone
-
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
, default5
Number of connections to the db to use
-
overflow
:int
, default10
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)
Close the connection
fetch¶
fetch(self, query: str)
Parameters¶
-
query
:str
SQL query string.
-
Fetches a query from the database and return as a list of lists
get_qa_checks¶
get_qa_checks(self, cdr_type: str, start_date: str, end_date: str, check_type: str) -> List[dict]
Returns deduped QA checks between start_date and end_date
Returns¶
typing.List
has_table¶
has_table(self, name: str, schema: Optional[str] = None) -> bool
Check if a table exists in the database.
Parameters¶
-
name
:str
Name of the table
-
schema
:typing.Optional
, defaultNone
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
Finds the maximum date in the given events table.
Parameters¶
-
table
:str
, defaultcalls
The table to check
Returns¶
datetime.date
min_date¶
min_date(self, table: str = 'calls') -> datetime.date
Finds the minimum date in the given events table.
Parameters¶
-
table
:str
, defaultcalls
The table to check
Returns¶
datetime.date
available_dates¶
available_dates
Returns¶
-
typing.Dict
Dict with tables as keys, containing lists of dates which are present
available_qa_checks¶
available_qa_checks
available_tables¶
available_tables
location_table¶
location_table
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
subscriber_tables¶
subscriber_tables
Class MissingCheckError¶
Source: flowmachine/core/connection.py
Common base class for all non-exit exceptions.