database_connector.database_connector

Database Objects

class Database(Enum)

Enum for the different supported databases. If you use MySQL, then use MARIADB as value here.

DatabaseConnector Objects

class DatabaseConnector()

Class for DatabaseConnector.

__init__

def __init__(database: Database, debug: bool = False)

Initializer for the DatabaseConnector

Arguments:

  • debug: boolean whether to print additional information while processing

connect

def connect(config: Dict = None, config_file_path: str = None, sqlite_file_path: str = None)

Wrapper method for connecting to the selected database.

Arguments:

host and port (default to host: localhost, port: 5432 if not given) for PostgreSQL or it has to be a
dictionary with at least database, user and password and optionally host and port (default to host:
localhost, port: 3306 if not given) for MariaDB.
if not given: The config file path is needed and used for these settings.
  • config: if given: It has to be a dictionary with at least db_name, user and password and optionally
  • config_file_path: Path to the config file for PostgreSQL or MariaDB.
  • sqlite_file_path: Path to the SQLite database file.

connect_to_postgres

def connect_to_postgres(config: Dict = None, config_file_path: str = "config.yaml")

Connect to the postgres database with the given config.

Arguments:

and port (default to host: localhost, port: 5432 if not given)
if not given: the config file 'config.yaml' is used for these settings
.yaml/.yml file
  • config: if given: it has to be a dictionary with at least db_name, user and password and optionally host
  • config_file_path: path for the config-file -> only necessary if no config is given; needs to point on a

connect_to_mariadb

def connect_to_mariadb(config: Dict = None, config_file_path: str = "config.yaml")

Connect to the postgres database with the given config.

Arguments:

and port (default to host: localhost, port: 3306 if not given)
if not given: the config file 'config.yaml' is used for these settings
.yaml/.yml file
  • config: if given: it has to be a dictionary with at least db_name, user and password and optionally host
  • config_file_path: path for the config-file -> only necessary if no config is given; needs to point on a

connect_to_sqlite

def connect_to_sqlite(database_file_path: str)

Open connection to a sqlite database.

Arguments:

  • database_file_path: The path to the sqlite database file.

close_database_connection

def close_database_connection()

close the connection to the database

Returns:

void

execute

def execute(sql_string: str)

Method for executing a SQL-Query.

Arguments:

  • sql_string: The SQL-Query to execute

fetchall

def fetchall()

Wrapper for fetchall method.

fetchone

def fetchone()

Wrapper for fetchone method.

results matching ""

    No results matching ""