src.digitaltwin.setup_environment

This script provides functions to set up the database connection using SQLAlchemy and environment variables, as well as to create an SQLAlchemy engine for database operations.

Attributes

log

Base

Functions

get_database(→ sqlalchemy.engine.Engine)

Set up the database connection. Exit the program if connection fails.

get_connection_from_profile(→ sqlalchemy.engine.Engine)

Sets up database connection from configuration.

get_engine(→ sqlalchemy.engine.Engine)

Get SQLAlchemy engine using credentials.

Module Contents

src.digitaltwin.setup_environment.log
src.digitaltwin.setup_environment.Base
src.digitaltwin.setup_environment.get_database() sqlalchemy.engine.Engine

Set up the database connection. Exit the program if connection fails.

Returns:

The engine used to connect to the database.

Return type:

Engine

Raises:

OperationalError – If the connection to the database fails.

src.digitaltwin.setup_environment.get_connection_from_profile() sqlalchemy.engine.Engine

Sets up database connection from configuration.

Returns:

The engine used to connect to the database.

Return type:

Engine

Raises:

ValueError – If one or more connection credentials are missing in the .env file.

src.digitaltwin.setup_environment.get_engine(host: str, port: str, db: str, username: str, password: str) sqlalchemy.engine.Engine

Get SQLAlchemy engine using credentials.

Parameters:
  • host (str) – Hostname of the database server.

  • port (str) – Port number.

  • db (str) – Database name.

  • username (str) – Username.

  • password (str) – Password for the database.

Returns:

The engine used to connect to the database.

Return type:

Engine