π§ͺ SQLAlchemy Databases¶
trulens_eval.database.sqlalchemy
¶
Attributes¶
Classes¶
SQLAlchemyDB
¶
Bases: DB
Database implemented using sqlalchemy.
See abstract class DB for method reference.
Attributes¶
table_prefix
class-attribute
instance-attribute
¶
table_prefix: str = DEFAULT_DATABASE_PREFIX
The prefix to use for all table names.
DB interface requirement.
engine_params
class-attribute
instance-attribute
¶
Sqlalchemy-related engine params.
session_params
class-attribute
instance-attribute
¶
Sqlalchemy-related session.
session
class-attribute
instance-attribute
¶
session: Optional[sessionmaker] = None
Sqlalchemy session(maker).
orm
instance-attribute
¶
Container of all the ORM classes for this database.
This should be set to a subclass of ORM upon initialization.
Functions¶
from_tru_args
classmethod
¶
from_tru_args(database_url: Optional[str] = None, database_file: Optional[str] = None, database_redact_keys: Optional[bool] = mod_db.DEFAULT_DATABASE_REDACT_KEYS, database_prefix: Optional[str] = mod_db.DEFAULT_DATABASE_PREFIX, **kwargs: Dict[str, Any]) -> SQLAlchemyDB
Process database-related configuration provided to the Tru class to create a database.
Emits warnings if appropriate.
from_db_url
classmethod
¶
from_db_url(url: str, **kwargs: Dict[str, Any]) -> SQLAlchemyDB
Create a database for the given url.
PARAMETER | DESCRIPTION |
---|---|
url |
The database url. This includes database type.
TYPE:
|
kwargs |
Additional arguments to pass to the database constructor. |
RETURNS | DESCRIPTION |
---|---|
SQLAlchemyDB
|
A database instance. |
delete_app
¶
delete_app(app_id: AppID) -> None
Deletes an app from the database based on its app_id.
PARAMETER | DESCRIPTION |
---|---|
app_id |
The unique identifier of the app to be deleted.
TYPE:
|
insert_feedback_definition
¶
insert_feedback_definition(feedback_definition: FeedbackDefinition) -> FeedbackDefinitionID
get_feedback_defs
¶
See DB.get_feedback_defs.
insert_feedback
¶
insert_feedback(feedback_result: FeedbackResult) -> FeedbackResultID
See DB.insert_feedback.
get_feedback_count_by_status
¶
get_feedback_count_by_status(record_id: Optional[RecordID] = None, feedback_result_id: Optional[FeedbackResultID] = None, feedback_definition_id: Optional[FeedbackDefinitionID] = None, status: Optional[Union[FeedbackResultStatus, Sequence[FeedbackResultStatus]]] = None, last_ts_before: Optional[datetime] = None, offset: Optional[int] = None, limit: Optional[int] = None, shuffle: bool = False) -> Dict[FeedbackResultStatus, int]
get_feedback
¶
get_feedback(record_id: Optional[RecordID] = None, feedback_result_id: Optional[FeedbackResultID] = None, feedback_definition_id: Optional[FeedbackDefinitionID] = None, status: Optional[Union[FeedbackResultStatus, Sequence[FeedbackResultStatus]]] = None, last_ts_before: Optional[datetime] = None, offset: Optional[int] = None, limit: Optional[int] = None, shuffle: Optional[bool] = False) -> DataFrame
See DB.get_feedback.
Functions¶
trulens_eval.database.orm
¶
Attributes¶
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
.
Functions¶
new_base
cached
¶
Create a new base class for ORM classes.
Note: This is a function to be able to define classes extending different SQLAlchemy delcarative 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
¶
Create a new orm container from the given base table class.
make_base_for_prefix
cached
¶
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:
|
table_prefix |
Prefix to use for table names.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Type[T]
|
A class that extends |
make_orm_for_prefix
cached
¶
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:
|