Database¶
Description
-
class
lab_utils.database.
Database
(config_file: str = None, host: str = None, port: int = None, database: str = None, user: str = None, passfile: str = None)[source]¶ Manages connections and operations with a PostgreSQL database. The class is based on the
psycopg2
library and on this tutorial.Attributes
Connection object returned by psycopg2.connect()
Cursor provided by _connection.cursor() to execute an SQL query
The database name to connect to
Database version
The host name where the database is located
Location of the pgpass file with the credentials
Connection port
User name
Methods
Initializes the
Database
object.Checks if a column exists in a given table.
Checks if a table exists.
Closes the connection to the database.
Loads the configuration.
Connects to the database.
Creates a TimescaleDB table.
Creates a new column in a given table.
Inserts data into a given table.