class documentation

class BaseRowFreeApiDB(ottoDB):

Constructor: BaseRowFreeApiDB(token)

View In Hierarchy

Undocumented

Class TABLES Undocumented
Method __init__ Initializes a BaseRowDB instance (inherits from qA_ApDB).
Method add_attribute_values Adds a attribute to the database. If the attribute already exists, it returns True without adding it again. If the attribute does not exist, it appends the attribute to the attributes file and returns True.
Method attribute_exists Checks if a attribute exists.
Method comment_exists Checks if a note exists for a specified document by a specified note_title.
Method get_all_documents_data Retrieves all documents data from the database. Each document is represented as a dictionary with "content" and "title" keys.
Method get_attribute_values Retrieves the attributes from the database. If the attributes file does not exist, it raises a FileNotFoundError.
Method get_catalog Retrieves the catalog. This method fetches the catalog from the database, which is stored in a JSON format. If the catalog does not exist, it raises a FileNotFoundError.
Method get_document Retrieves the content and icon of a specified document.
Method get_document_medias Retrieves the base64-encoded images for a specified document from the POSTS_MEDIAS table.
Method get_note_medias Retrieves the base64-encoded images for a specified note of a document from the COMMENTS_MEDIAS table.
Method get_notes_for_post Retrieves notes for a specified document, with pagination support. If perpage is set to 0, all notes will be returned without pagination. If the pagination parameters are invalid, an empty list will be returned.
Method get_vector_store Retrieves the vector store from the database.
Method post_exists Checks if a document exists.
Method write_attribute Writes attributes to the database. If the attributes file already exists, it updates the content. If the attributes file does not exist, it creates a new file with the specified attributes.
Method write_catalog Writes the catalog to the database. If the catalog already exists, it updates the content. If the catalog does not exist, it creates a new file with the specified JSON content.
Method write_comment Writes a note to a specified document. If the document does not exist, it raises a FileNotFoundError. If the note already exists, it raises a FileAlreadyExistsError.
Method write_post Writes a document to the database. If the document already exists, it raises a FileAlreadyExistsError.
Method write_vector_store Writes the vector store to the database.
Instance Variable token Undocumented
Method _filter_by_fields_value Constructs a filter dictionary for querying the BaseRow API. This method creates a filter that matches rows based on specified field-value pairs.
Method _get Makes a GET request to the BaseRow API to retrieve rows from a specified table. WARNNING: Only the fields listed in the include parameter can be used in the filters parameter.
Method _include_fields Constructs an include string for querying the BaseRow API.
Method _post Makes a POST request to the BaseRow API to create a new row in a specified table. This method is not implemented and should be overridden in subclasses.
Method _update Makes a POST request to the BaseRow API to create a new row in a specified table. This method is not implemented and should be overridden in subclasses.
def __init__(self, token: str):

Initializes a BaseRowDB instance (inherits from qA_ApDB). Args: token (str): The API token for authentication with the BaseRow API.

def add_attribute_values(self, attribute: str, data: str) -> bool:

Adds a attribute to the database. If the attribute already exists, it returns True without adding it again. If the attribute does not exist, it appends the attribute to the attributes file and returns True. Args: attribute (str): The attribute to add. Returns: bool: True if the attribute was added successfully, False if it already exists. Raises: WriteInDatabaseError: If there is an error writing to the attributes file.

def attribute_exists(self, attribute: str, value: str) -> bool:

Checks if a attribute exists. Args: attribute (str): Name of the attribute to check. Returns: bool: True if the attribute exists, False otherwise. Raises: FileNotFoundError: If the attributes does not exist in the database.

def comment_exists(self, post_title: str, note_title: str) -> bool:

Checks if a note exists for a specified document by a specified note_title. Args: post_title (str): Name of the document. note_title (str): Name of the note_title. Returns: bool: True if the note exists, False otherwise.

def get_all_documents_data(self) -> list[dict[str, str]]:

Retrieves all documents data from the database. Each document is represented as a dictionary with "content" and "title" keys. Returns: list[dict[str,str]]: A list of dictionaries containing the content and title of each document. Raises: FileNotFoundError: If no documents are found in the database.

def get_attribute_values(self, attribute: str) -> str:

Retrieves the attributes from the database. If the attributes file does not exist, it raises a FileNotFoundError. Returns: str: The attributes as a string, with each value on a new line. Raises: FileNotFoundError: If the attributes file is not found in the database.

def get_catalog(self) -> str:

Retrieves the catalog. This method fetches the catalog from the database, which is stored in a JSON format. If the catalog does not exist, it raises a FileNotFoundError. Returns: str: The catalog as a JSON string. Raises: FileNotFoundError: If the catalog is not found in the database.

def get_document(self, post_title: str) -> tuple[str, str]:

Retrieves the content and icon of a specified document. Args: post_title (str): Name of the document to retrieve. Returns: tuple[str,str]: A tuple containing the document content and the icon in base64 format. Raises: FileNotFoundError: If the document does not exist in the database.

def get_document_medias(self, post_title: str, includes: list[str] = []) -> list[str]:

Retrieves the base64-encoded images for a specified document from the POSTS_MEDIAS table. Args: post_title (str): Name of the document. includes (list[str]): List of image file stems to include (e.g., ["screen1", "screen2"]). Returns: list[str]: A list of base64-encoded images for the document. Raises: FileNotFoundError: If the document does not exist.

def get_note_medias(self, post_title: str, note_title: str, includes: list[str] = []) -> list[str]:

Retrieves the base64-encoded images for a specified note of a document from the COMMENTS_MEDIAS table. Args: post_title (str): Name of the document. note_title (str): Name of the note_title. includes (list[str]): List of image file stems to include. Returns: list[str]: A list of base64-encoded images for the note. Raises: FileNotFoundError: If the note does not exist.

def get_notes_for_post(self, post_title: str, perpage: int = 0, page: int = 1) -> list[tuple[str, str, str]]:

Retrieves notes for a specified document, with pagination support. If perpage is set to 0, all notes will be returned without pagination. If the pagination parameters are invalid, an empty list will be returned. Args: post_title (str): Name of the document to retrieve notes for. perpage (int): Number of notes to return per page (0 for no pagination). page (int): Page number to retrieve (0-based index). Returns: list[str]: A list of notes for the specified document. Raises: FileNotFoundError: If the document does not exist or if no notes are found.

def get_vector_store(self) -> bytes:

Retrieves the vector store from the database. Returns: bytes: The vector store data in bytes format. Raises: FileNotFoundError: If the vector store is not found in the database.

def post_exists(self, post_title: str) -> bool:

Checks if a document exists. Args: post_title (str): Name of the document to check. Returns: bool: True if the document exists, False otherwise.

def write_attribute(self, attribute: str, data: str) -> bool:

Writes attributes to the database. If the attributes file already exists, it updates the content. If the attributes file does not exist, it creates a new file with the specified attributes. Args: attributes (str): The attributes to write, separated by new lines. Returns: bool: True if the write operation was successful. Raises: WriteInDatabaseError: If there is an error writing to the attributes file.

def write_catalog(self, json: str):

Writes the catalog to the database. If the catalog already exists, it updates the content. If the catalog does not exist, it creates a new file with the specified JSON content. Args: json (str): The JSON content to write to the catalog. Returns: bool: True if the write operation was successful. Raises: WriteInDatabaseError: If there is an error writing to the catalog file.

def write_comment(self, post_title: str, note_title: str, content: str, medias: list[tuple[str, str]] = []) -> bool:

Writes a note to a specified document. If the document does not exist, it raises a FileNotFoundError. If the note already exists, it raises a FileAlreadyExistsError. Args: post_title (str): Name of the document to note on. note_title (str): Name of the note_title. content (str): Content of the note. medias (list[str]): List of base64 encoded screenshots for the note. Returns: bool: True if the write operation was successful. Raises: FileNotFoundError: If the document does not exist. FileAlreadyExistsError: If the note already exists. WriteInDatabaseError: If there is an error writing to the database.

def write_post(self, post_title: str, content: str, icon: str = '', medias: list[tuple[str, str]] = []) -> bool:

Writes a document to the database. If the document already exists, it raises a FileAlreadyExistsError. Args: post_title (str): Name of the document to write. icon (str): Base64 encoded icon for the document. media (list[str]): List of base64 encoded media for the document. content (str): Content of the document. Returns: bool: True if the write operation was successful. Raises: FileAlreadyExistsError: If the document already exists. WriteInDatabaseError: If there is an error writing to the database.

def write_vector_store(self, bytes_data: bytes) -> bool:

Writes the vector store to the database. Args: bytes_data (bytes): The vector store data in bytes format. Returns: bool: True if the write operation was successful. Raises: WriteInDatabaseError: If there is an error writing to the vector store.

token =

Undocumented

def _filter_by_fields_value(self, fields: list[tuple[str, str]], orfields: list[tuple[str, str]] = []) -> str:

Constructs a filter dictionary for querying the BaseRow API. This method creates a filter that matches rows based on specified field-value pairs. Args: fields (list[tuple[str,str]]): A list of tuples where each tuple contains a field name and its corresponding value. Returns: dict[str, str]: A dictionary representing the filter.

def _get(self, table: TABLES, include: list[str] = None, filters: list[tuple[str, str]] = None, orfilters: list[tuple[str, str]] = [], page: int = None, size: int = None) -> list[dict]:

Makes a GET request to the BaseRow API to retrieve rows from a specified table. WARNNING: Only the fields listed in the include parameter can be used in the filters parameter. Args: table (TABLES): The table to query, specified as a TABLES enum. include (list[str], optional): A list of field names to include in the response. Defaults to None (all fields are used). filters (list[tuple[str,str]], optional): A list of tuples where each tuple contains a field name and its corresponding value for filtering. Defaults to None (no filter is applied). page (str, optional): The page number to retrieve. Defaults to 1. size (str, optional): The number of rows to retrieve per page. Defaults to 100. Returns: list[dict]: A list of dictionaries representing the rows that match the query.

def _include_fields(self, fields: list[str]) -> str:

Constructs an include string for querying the BaseRow API. Args: fields (list[str]): A list of field names to include in the query. Returns: str: A string representing the fields to include.

def _post(self, table: TABLES, body: dict, batchmode: bool = False) -> list[dict]:

Makes a POST request to the BaseRow API to create a new row in a specified table. This method is not implemented and should be overridden in subclasses. Args: table (TABLES): The table to which the new row will be added. Returns: list[dict]: A list of dictionaries representing the newly created row(s). Raises: NotImplementedError: This method is not implemented.

def _update(self, table: TABLES, row_id: int, field_name: str, content: str) -> bool:

Makes a POST request to the BaseRow API to create a new row in a specified table. This method is not implemented and should be overridden in subclasses. Args: table (TABLES): The table to which the new row will be added. Returns: list[dict]: A list of dictionaries representing the newly created row(s). Raises: NotImplementedError: This method is not implemented.