Source code for tisserande.db.nodes

"""ORM model for the Node table (single table for all node types).

All node types (data files, config files, parameters, arrays, objects,
python functions, member functions, shell functions) share this one table.
Type-specific fields are nullable columns. This design simplifies graph
queries since edges only reference one table.
"""

import uuid

from pydantic import BaseModel
from sqlalchemy import JSON, Float, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column

from .. import models
from .base import Base


def _uuid7() -> uuid.UUID:
    import uuid_utils
    return uuid.UUID(str(uuid_utils.uuid7()))


[docs] class NodeTable(Base): __tablename__ = "node"
[docs] id_: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=_uuid7)
[docs] type_: Mapped[str] = mapped_column(String(50), index=True)
[docs] execution_id: Mapped[uuid.UUID | None] = mapped_column( ForeignKey("execution.id_"), nullable=True, index=True, )
[docs] path: Mapped[str | None] = mapped_column(String(1024), nullable=True)
[docs] config_data: Mapped[dict | None] = mapped_column(JSON, nullable=True)
[docs] value_float: Mapped[float | None] = mapped_column(Float, nullable=True)
[docs] value_json: Mapped[dict | list | None] = mapped_column(JSON, nullable=True)
[docs] arg_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
[docs] data_file_type_id: Mapped[int | None] = mapped_column( ForeignKey("data_file_type.id_"), nullable=True, )
[docs] config_file_type_id: Mapped[int | None] = mapped_column( ForeignKey("config_file_type.id_"), nullable=True, )
[docs] config_dict_type_id: Mapped[int | None] = mapped_column( ForeignKey("config_dict_type.id_"), nullable=True, )
[docs] parameter_id: Mapped[int | None] = mapped_column( ForeignKey("parameter.id_"), nullable=True, )
[docs] array_id: Mapped[int | None] = mapped_column( ForeignKey("array.id_"), nullable=True, )
[docs] class_id: Mapped[int | None] = mapped_column( ForeignKey("class.id_"), nullable=True, )
[docs] python_function_id: Mapped[int | None] = mapped_column( ForeignKey("python_function.id_"), nullable=True, )
[docs] member_function_id: Mapped[int | None] = mapped_column( ForeignKey("member_function.id_"), nullable=True, )
[docs] shell_function_id: Mapped[int | None] = mapped_column( ForeignKey("shell_function.id_"), nullable=True, )
@classmethod
[docs] def pydantic_create_class(cls) -> type[BaseModel]: return models.NodeCreate
@classmethod
[docs] def pydantic_model_class(cls) -> type[BaseModel]: return models.Node
@classmethod
[docs] def class_string(cls) -> str: return cls.__tablename__