Skip to content

trulens.core.database.orm

trulens.core.database.orm

Attributes

TYPE_JSON module-attribute

TYPE_JSON = Text

Database type for JSON fields.

TYPE_TIMESTAMP module-attribute

TYPE_TIMESTAMP = Float

Database type for timestamps.

TYPE_ENUM module-attribute

TYPE_ENUM = Text

Database type for enum fields.

TYPE_ID module-attribute

TYPE_ID = VARCHAR(256)

Database type for unique IDs.

Classes

BaseWithTablePrefix

ORM base class except with __tablename__ defined in terms of a base name and a prefix.

A subclass should set _table_base_name and/or _table_prefix. If it does not set both, make sure to set __abstract__ = True. Current design has subclasses set _table_base_name and then subclasses of that subclass setting _table_prefix as in make_orm_for_prefix.

ORM

Bases: ABC, Generic[T]

Abstract definition of a container for ORM classes.

Functions

new_base cached

new_base(prefix: str) -> Type[T]

Create a new base class for ORM classes.

Note: This is a function to be able to define classes extending different SQLAlchemy declarative bases. Each different such bases has a different set of mappings from classes to table names. If we only had one of these, our code will never be able to have two different sets of mappings at the same time. We need to be able to have multiple mappings for performing things such as database migrations and database copying from one database configuration to another.

new_orm

new_orm(base: Type[T]) -> Type[ORM[T]]

Create a new orm container from the given base table class.

make_base_for_prefix cached

make_base_for_prefix(
    base: Type[T],
    table_prefix: str = DEFAULT_DATABASE_PREFIX,
) -> Type[T]

Create a base class for ORM classes with the given table name prefix.

PARAMETER DESCRIPTION
base

Base class to extend. Should be a subclass of BaseWithTablePrefix.

TYPE: Type[T]

table_prefix

Prefix to use for table names.

TYPE: str DEFAULT: DEFAULT_DATABASE_PREFIX

RETURNS DESCRIPTION
Type[T]

A class that extends base_type and sets the table prefix to table_prefix.

make_orm_for_prefix cached

make_orm_for_prefix(
    table_prefix: str = DEFAULT_DATABASE_PREFIX,
) -> Type[ORM[T]]

Make a container for ORM classes.

This is done so that we can use a dynamic table name prefix and make the ORM classes based on that.

PARAMETER DESCRIPTION
table_prefix

Prefix to use for table names.

TYPE: str DEFAULT: DEFAULT_DATABASE_PREFIX