dav_tools.database

Database interaction

Classes

PostgreSQL

Connection with a PostgreSQL database

Module Contents

class dav_tools.database.PostgreSQL(host, port, database, user, password)

Connection with a PostgreSQL database

Parameters:
  • host (str)

  • port (int)

  • database (str)

  • user (str)

  • password (str)

insert(schema, table, data, return_fields=[])

Inserts a row into a specified table within a PostgreSQL database.

Parameters:
  • schema (str) – The schema name where the table resides.

  • table (str) – The name of the table to insert data into.

  • data (dict[str, Any]) – A dictionary where keys are column names and values are the data to insert.

  • return_fields (list[str]) – A list of fields to return after the insert. Defaults to an empty list.

Returns:

If return_fields is specified, returns a tuple containing the values of the requested fields. Otherwise, returns None.

Notes:
  • The data dictionary keys must match the column names of the table.

Return type:

list[tuple[str, Any]] | None