Database¶
Description
- class lab_utils.database.Database(config_file: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None, database: Optional[str] = None, user: Optional[str] = None, passfile: Optional[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 whether a table is empty or not
Checks if a table exists.
Closes the connection to the database.
Loads the configuration.
Connects to the database.
Creates a set of aggregate views in a given table.
Creates a database named
db_name
.Creates a TimescaleDB table.
Retrieves the latest values of a time-ordered table.
Checks the latest ID of a serialized table and returns the next available one.
Fetches the list of columns in a given table.
Creates a new column in a given table.
Inserts data into a given table.
Retrieves entries from a table with given conditions.
Updates the entry of a measurement.