pipert.contrib.database.handler¶
Module Contents¶
Classes¶
Functions¶
|
Formats the error messages from SQLAlchemy exceptions and cleans them up a bit. |
-
class
pipert.contrib.database.handler.PSQLDBHandler(db_conf: dict, logger)[source]¶ -
test_connection(self) → bool[source]¶ Test the connection to the currently configured DataBase.
- Returns:
True if has connection, False otherwise
-
property
session(self)[source]¶ Exposes the session for syntactic-sugar purposes
Returns: The current session
-
abstract
define_tables(self, *args, **kwargs)[source]¶ Any table that should be used by the handler must be defined and registered in ‘self.tables’ inside this method.
- Args:
*args: (Optional) Any required positional arguments **kwargs: (Optional) Any required keyword arguments
Example usage (bare bones):
# Define one or more tables.. class User(self.db.Model):
__tablename__ = ‘users’ user_id = Column(Integer, primary_key=True) user_name = Column(Integer, nullable=False) user_birth_date = Column(DateTime)
- def __init__(self, user_id, name, dob):
self.user_id = user_id self.user_name = name self.user_birth_date = dob
# Then register them self.tables[User.__tablename__] = User
-
-
pipert.contrib.database.handler.format_sqla_error(err_: str, sqlalchemy.exc.SQLAlchemyError) → str[source]¶ Formats the error messages from SQLAlchemy exceptions and cleans them up a bit.
- Args:
err_: SQLAlchemy exception or the error message of such an exception.
- Returns:
Formatted string representation of the error in question.