flip_api.model_services.retrieve_model

Attributes

RETRIEVE_MODEL_QUERY_FILE

Functions

load_sql(→ str)

Load an SQL query from a file.

parse_query_from_result(...)

Parse a query from the SQL result into an IQuery object.

parse_files_from_result(...)

Parse files from the SQL result into a list of UploadedFiles objects.

retrieve_model(, db, user_id)

Retrieve a model by its ID. Returns the model details, including its status, associated files, and query.

Module Contents

flip_api.model_services.retrieve_model.RETRIEVE_MODEL_QUERY_FILE
flip_api.model_services.retrieve_model.load_sql(file_path: str) str

Load an SQL query from a file.

Parameters:

file_path (str) – Absolute or relative path to the .sql file.

Returns:

The file contents.

Return type:

str

flip_api.model_services.retrieve_model.parse_query_from_result(query: Any) flip_api.domain.interfaces.model.IQuery

Parse a query from the SQL result into an IQuery object.

Parameters:

query (Any) – Mapping-like row from the raw SQL result with id, name, and query keys.

Returns:

The parsed query domain object.

Return type:

IQuery

flip_api.model_services.retrieve_model.parse_files_from_result(files: Any, model_id: uuid.UUID) list[flip_api.db.models.main_models.UploadedFiles]

Parse files from the SQL result into a list of UploadedFiles objects.

Parameters:
  • files (Any) – Iterable of mapping-like rows with id, name, status, size, type, and tag keys.

  • model_id (UUID) – The model ID that each parsed file should be attributed to.

Returns:

Parsed uploaded-file records. Rows with an unknown status are mapped to FileUploadStatus.ERROR.

Return type:

list[UploadedFiles]

flip_api.model_services.retrieve_model.retrieve_model(model_id: uuid.UUID = Path(..., title='Model ID'), db: sqlmodel.Session = Depends(get_session), user_id: uuid.UUID = Depends(verify_token)) flip_api.domain.interfaces.model.IModelResponse

Retrieve a model by its ID. Returns the model details, including its status, associated files, and query.

The user must have access to the model to retrieve its details. If the model is not found or the user does not have access, an error is returned.

Parameters:
  • model_id (UUID) – The ID of the model to retrieve.

  • db (Session) – The database session.

  • user_id (UUID) – The ID of the current user.

Returns:

The details of the model, including its ID, name, description, status, query, and files.

Return type:

IModelResponse

Raises:
  • HTTPException – If the user does not have access to the model or if the model is not found.

  • HTTPException – If there is a database error while retrieving the model.

  • HTTPException – If an unexpected error occurs during the retrieval process.