Database

Description

class lab_utils.database.Database(config_file: str = None)[source]

Manages connections and operations with a PostgreSQL database. The class is based on the psycopg2 library and on this tutorial.

Attributes

Database.connection

Connection object returned by psycopg2.connect()

Database.cursor

Cursor provided by _connection.cursor() to execute an SQL query

Database.database

The database name to connect to

Database.db_version

Database version

Database.host

The host name where the database is located

Database.logger

Single logger for the whole class.

Database.passfile

Location of the pgpass file with the credentials

Database.port

Connection port

Database.user

User name

Methods

Database.__init__

Initializes the Database object.

Database.check_column

Checks if a column exists in a given table.

Database.check_table

Checks if a table exists.

Database.close

Closes the connection to the database.

Database.config

Loads the configuration.

Database.connect

Connects to the database.

Database.create_timescale_db

Creates a TimescaleDB table.

Database.new_column

Creates a new column in a given table.

Database.new_entry

Inserts data into a given table.