Skip to main content

sqlalchemy_connection

class atscale.db.sqlalchemy_connection.SQLAlchemyConnection

An abstract class that adds common functionality for SQLAlchemy to reduce duplicate code in implementing classes. SQLAlchemy does not support all databases, so some classes may need to implement SQLConnection directly.

dispose_engine

Use this method to close the engine and any associated connections in its connection pool.

If the user changes the connection parameters on an sql_connection object then dispose() should be called so any current connections (and engine) is cleared of all state before establishing a new connection (and engine and connection pool). Probably don’t want to call this in other situations. From the documentation: https://docs.sqlalchemy.org/en/13/core/connections.html#engine-disposal

execute_statements

Executes a list of SQL statements. Does not return any results but may trigger an exception.

  • Parameters: statement_list (list) – a list of SQL statements to execute.

submit_queries

Submits a list of queries, collecting the results in a list of dictionaries.

  • Parameters: query_list (list) – a list of queries to submit.
  • Returns: A list of pandas DataFrames containing the results of the queries.
  • Return type: List(DataFrame)

write_df_to_db

Writes the provided pandas DataFrame into the provided table name. Can pass in if_exists to indicate the intended behavior if : the provided table name is already taken.

  • Parameters:
    • table_name (str) – What table to write the dataframe into
    • dataframe (DataFrame) – The pandas DataFrame to write into the table
    • dtypes (Dict , optional) – the datatypes of the passed dataframe. Keys should match the column names. Defaults to None and type will be text.
    • if_exists (enums.TableExistsAction , optional) – The intended behavior in case of table name collisions. Defaults to enums.TableExistsAction.ERROR.
    • chunksize (int , optional) – the chunksize for the write operation.