Skip to content

CLI Bases Resource

CLIBasesResource(cli)

Bases: BaseCLIResource

CLI resource for Obsidian Bases (database) operations.

Attributes:

Name Type Description
_cli

Reference to the parent ObsidianCLI instance.

Source code in src/aiobsidian/cli/_base.py
def __init__(self, cli: ObsidianCLI) -> None:
    self._cli = cli

views(path) async

List views of a database file.

Parameters:

Name Type Description Default
path str

Path to the database file.

required

Returns:

Type Description
list[dict[str, Any]]

List of view objects.

Source code in src/aiobsidian/cli/bases.py
async def views(self, path: str) -> list[dict[str, Any]]:
    """List views of a database file.

    Args:
        path: Path to the database file.

    Returns:
        List of view objects.
    """
    output = await self._cli._execute("base:views", params={"file": path})
    result: list[dict[str, Any]] = json.loads(output)
    return result

create(path, **fields) async

Create a record in a database.

Parameters:

Name Type Description Default
path str

Path to the database file.

required
**fields str

Field name-value pairs for the new record.

{}
Source code in src/aiobsidian/cli/bases.py
async def create(self, path: str, **fields: str) -> None:
    """Create a record in a database.

    Args:
        path: Path to the database file.
        **fields: Field name-value pairs for the new record.
    """
    params: dict[str, str] = {"file": path}
    params.update(fields)
    await self._cli._execute("base:create", params=params)

query(path, *, view=None) async

Query records from a database.

Parameters:

Name Type Description Default
path str

Path to the database file.

required
view str | None

Optional view name to filter by.

None

Returns:

Type Description
list[dict[str, Any]]

List of record objects.

Source code in src/aiobsidian/cli/bases.py
async def query(
    self, path: str, *, view: str | None = None
) -> list[dict[str, Any]]:
    """Query records from a database.

    Args:
        path: Path to the database file.
        view: Optional view name to filter by.

    Returns:
        List of record objects.
    """
    params: dict[str, str] = {"file": path}
    if view:
        params["view"] = view
    output = await self._cli._execute("base:query", params=params)
    result: list[dict[str, Any]] = json.loads(output)
    return result

list() async

List all database files in the vault.

Returns:

Type Description
list[dict[str, Any]]

List of database file objects.

Source code in src/aiobsidian/cli/bases.py
async def list(self) -> list[dict[str, Any]]:
    """List all database files in the vault.

    Returns:
        List of database file objects.
    """
    output = await self._cli._execute("bases")
    result: list[dict[str, Any]] = json.loads(output)
    return result