Skip to content

Collection

Methods for working with collections.

Collection

Methods for working with collections.

Source code in src/scruby/mixins/collection.py
class Collection:
    """Methods for working with collections."""

    @final
    def collection_name(self) -> str:
        """Asynchronous method for getting the collection name.

        Returns:
            Collection name.
        """
        return self._class_model.__name__

    @final
    @staticmethod
    async def collection_list() -> list[str]:
        """Asynchronous method for getting collection list."""
        target_directory = Path(ScrubySettings.db_root)
        # Get all entries in the directory
        all_entries = Path.iterdir(target_directory)
        directory_names: list[str] = [entry.name async for entry in all_entries]
        return directory_names

    @final
    @staticmethod
    async def delete_collection(name: str) -> None:
        """Asynchronous method for deleting a collection by its name.

        Args:
            name (str): Collection name.

        Returns:
            None.
        """
        target_directory = f"{ScrubySettings.db_root}/{name}"
        await to_thread.run_sync(rmtree, target_directory)  # pyrefly: ignore[bad-argument-type]
        return

collection_list() async staticmethod

Asynchronous method for getting collection list.

Source code in src/scruby/mixins/collection.py
@final
@staticmethod
async def collection_list() -> list[str]:
    """Asynchronous method for getting collection list."""
    target_directory = Path(ScrubySettings.db_root)
    # Get all entries in the directory
    all_entries = Path.iterdir(target_directory)
    directory_names: list[str] = [entry.name async for entry in all_entries]
    return directory_names

collection_name()

Asynchronous method for getting the collection name.

Returns:

Type Description
str

Collection name.

Source code in src/scruby/mixins/collection.py
@final
def collection_name(self) -> str:
    """Asynchronous method for getting the collection name.

    Returns:
        Collection name.
    """
    return self._class_model.__name__

delete_collection(name) async staticmethod

Asynchronous method for deleting a collection by its name.

Parameters:

Name Type Description Default
name str

Collection name.

required

Returns:

Type Description
None

None.

Source code in src/scruby/mixins/collection.py
@final
@staticmethod
async def delete_collection(name: str) -> None:
    """Asynchronous method for deleting a collection by its name.

    Args:
        name (str): Collection name.

    Returns:
        None.
    """
    target_directory = f"{ScrubySettings.db_root}/{name}"
    await to_thread.run_sync(rmtree, target_directory)  # pyrefly: ignore[bad-argument-type]
    return