Table of Contents

openeo_fastapi.client.psql.engine

Standardisation of common functionality to interact with the ORMs and the database.

get_engine

def get_engine()

Get the engine using config from pydantic settings.

Returns:

  • Engine - The engine instance that was created.

Filter Objects

class Filter(BaseModel)

Filter class to assist with providing a filter by funciton with values across different cases.

create

def create(create_object: BaseModel) -> bool

Add the values from a pydantic model to the database using its respective object relational mapping.

get

def get(get_model: BaseModel, primary_key: Any) -> Union[None, BaseModel]

Get the relevant entry for a given model using the provided primary key value.

Arguments:

  • get_model BaseModel - The model that to get from the database.
  • primary_key Any - The primary key of the model instance to get.

Returns:

Union[None, BaseModel]: None, or the found model

modify

def modify(modify_object: BaseModel) -> bool

Modify the relevant entries for a given model instance

Arguments:

  • modify_object BaseModel - An instance of a pydantic model that reflects a change to make in the database.

Returns:

  • bool - Whether the change was successful.

delete

def delete(delete_model: BaseModel, primary_key: Any) -> bool

Delete the values from a pydantic model in the database using its respective object relational mapping.

Arguments:

  • delete_model BaseModel - The model that to delete from the database.
  • primary_key Any - The primary key of the model instance to delete.

Returns:

  • bool - Whether the change was successful.

get_first_or_default

def get_first_or_default(get_model: BaseModel,
                         filter_with: Filter) -> BaseModel

Perform a list operation and return the first found instance.

Arguments:

  • get_model BaseModel - The model that to get from the database.
  • filter_with Filter - Filter of a Key/Value pair to apply to the model.

Returns:

Union[None, BaseModel]: Return the model if found, else return None.