actions.db_connector

File contains:
  • a class that connects to a database and methods to query it.

  • a function to create a string of questionmarks.

Module Contents

Classes

DBConnector

Connects to the database and allows queries.

Functions

create_string(→ str)

Creates a string with questionmarks.

class actions.db_connector.DBConnector(filename='dagfinn')

Connects to the database and allows queries.

Parameters

filename – Name of the database file.

create_table(name: str, content: str) None

Creates a table in the database.

Parameters
  • name – The name of the table.

  • content – A string with the column names and types.

delete_table(table: str) None

Deletes a table from the database.

Parameters

table – Name of the table to be deleted.

insert(table: DBConnector.insert.str, content: tuple) None

Inserts data into the given table. Ignores if row already exists.

Parameters
  • table – The table the data will be inserted into.

  • content – A tuple of data to be inserted.

insert_with_fields(table: DBConnector.insert_with_fields.str, content: dict) None

Inserts data in specific fields into the given table. Ignores if row already exists. :param table: The table the data will be inserted into. :param content: A dictionary of data with keys being fields of the table

delete(table: str, parameters: str) None

Deletes a row with certain parameters.

Parameters
  • table – The table the row will be deleted from.

  • parameters – A string with the deletion requirements.

update(table: str, change: str, parameters: str) None

Updates a row with the given parameters.

Parameters
  • table – The table in which the row will be updated in.

  • change – The data to be changed.

  • parameters – The required data for the update.

select(table: str, select: str) list

Selects columns from the database.

Parameters
  • table – The table to select from.

  • select – The columns to select.

Returns

The columns from the database.

select_where(table: str, column: str, where: str) list

Selects columns from the database with parameters.

Parameters
  • table – The table to select from.

  • column – The columns to select.

  • where – The parameters to filter by, e.g Id > 2

Returns

The columns from the database.

actions.db_connector.create_string(amount: int) str

Creates a string with questionmarks.

Parameters

amount – The amount of questionmarks or entries.

Returns

?, ?, ?

Return type

A string with questionmarks, for example