florist.api.db.client_entities module

Definitions for the SQLIte database entities (client database).

class ClientDAO(uuid, log_file_path=None, pid=None)[source]

Bases: EntityDAO

Data Access Object (DAO) for the Client SQLite entity.

__init__(uuid, log_file_path=None, pid=None)[source]

Initialize a Client entity.

Parameters:
  • uuid (str) – (str) the UUID of the client.

  • log_file_path (Optional[str]) – the path in the filesystem where the client’s log can be located.

  • pid (Optional[int]) – the PID of the client’s process.

classmethod from_json(json_data)[source]

Convert from a JSON string into an instance of Client.

Parameters:

json_data (str) – the client’s data as a JSON string.

Return type:

Self

Returns:

(Self) and instancxe of ClientDAO populated with the JSON data.

table_name = 'Client'
to_json()[source]

Convert the client data into a JSON string.

Return type:

str

Returns:

(str) the client data as a JSON string.

class EntityDAO(uuid)[source]

Bases: ABC

Base Data Access Object (DAO) for SQLite entities.

abstract __init__(uuid)[source]

Initialize an Entity.

Abstract method to be implemented by the child classes.

Parameters:

uuid (str) – the UUID of the entity

db_path = 'florist/api/client.db'
classmethod exists(uuid)[source]

Check if an entity with the given UUID exists in the database.

Parameters:

uuid (str) – (str) the UUID of the entity.

Return type:

bool

Returns:

(bool) True if the entity exists, False otherwise.

classmethod find(uuid)[source]

Find the entity in the database with the given UUID.

Parameters:

uuid (str) – (str) the UUID of the entity.

Return type:

Self

Returns:

(Self) an instance of the entity.

Raises:

ValueError – if no such entity exists in the database with given UUID.

abstract classmethod from_json(json_data)[source]

Convert from a JSON string to an instance of the entity.

Abstract method, to be implemented by the child classes.

Parameters:

json_data (str) – (str) the entity data as a JSON string.

Return type:

Self

Returns:

(Self) and instance of the entity populated with the JSON data.

classmethod get_connection()[source]

Return the SQLite connection object.

Will create the table of the entity in the DB if it doesn’t exist.

Return type:

Connection

Returns:

(sqlite3.Connection) The SQLite connection object

save()[source]

Save the current entity to the database.

Return type:

None

Will insert a new record if an entity with self.uuid doesn’t yet exist in the database,

will update the database entity at self.uuid otherwise.

table_name = 'Entity'
abstract to_json()[source]

Convert the entity data into a JSON string.

Abstract method, to be implemented by the child classes.

Return type:

str

Returns:

(str) the entity data as a JSON string.