file2document_service.py


Overview

file2document_service.py defines the File2DocumentService class, which provides database service methods managing the relationships between files and documents within the InfiniFlow application. It acts as a specialized service layer to perform CRUD (Create, Read, Update, Delete) operations on the File2Document model, which represents the many-to-many or associative relationship between File and Document entities.

This service abstracts direct database access and offers utility methods to query, insert, update, and delete file-document linkage records, as well as retrieving storage locations related to files or documents.


Classes and Methods

Class: File2DocumentService

File2DocumentService extends CommonService and operates primarily on the File2Document database model. It uses decorators to ensure all database operations run within a proper database connection context (@DB.connection_context()).


Attributes


Methods

get_by_file_id(file_id)


get_by_document_id(document_id)


insert(obj)


delete_by_file_id(file_id)


delete_by_document_id(doc_id)


update_by_file_id(file_id, obj)


get_storage_address(doc_id=None, file_id=None)


Important Implementation Details


Interaction With Other Components

This service acts as a middle layer between the database layer and higher application logic that needs to manage or query file-document relationships and their storage locations.


Mermaid Class Diagram

classDiagram
    class File2DocumentService {
        <<Service>>
        +model: File2Document
        +get_by_file_id(file_id)
        +get_by_document_id(document_id)
        +insert(obj)
        +delete_by_file_id(file_id)
        +delete_by_document_id(doc_id)
        +update_by_file_id(file_id, obj)
        +get_storage_address(doc_id=None, file_id=None)
    }

    File2DocumentService --|> CommonService
    File2DocumentService ..> File2Document : uses
    File2DocumentService ..> File : queries
    File2DocumentService ..> DocumentService : interacts

Summary

The File2DocumentService class encapsulates all database operations related to the File2Document model, which links files and documents in the InfiniFlow system. It provides methods to retrieve, insert, update, and delete these associations, along with a utility to find storage locations based on either a file or document ID. This modular design simplifies managing file-document relationships and abstracts underlying database complexities, ensuring consistent and safe data operations.