text: import logging
  
  from sqlalchemy import exc, select, or_
  from sqlalchemy.orm import contains_eager, load_only
  from werkzeug.exceptions import abort
  
  from app import db
  from app.models import Landlord, Rent
  
  
  dbLogger = logging.getLogger("dbLogger")
  
  
  # def load_rent_table():
  #     stmt = select(Rent).join(Rent.prop_rent).join(Landlord).outerjoin(Rent.charge_rent) \
  #         .options(contains_eager(Rent.prop_rent),
  #                  contains_eager(Rent.charge_rent),
  #                  load_only('rentcode', 'tenantname', 'rentpa', 'arrears', 'lastrentdate', 'source', 'price', 'email',
  #                            'landlord_id', 'agent_id', 'actype_id', 'advarr_id', 'deed_id', 'freq_id', 'mailto_id',
  #                            'prdelivery_id', 'salegrade_id', 'status_id', 'tenure_id', 'datecode_id'))
  #     return db.session.execute(stmt).unique().scalars().all()
  
  
  def load_rents_check_basic(filtr):
      stmt = select(Rent).outerjoin(Rent.prop_rent) \
          .options(contains_eager(Rent.prop_rent).load_only('propaddr'))
      return db.session.execute(stmt.filter(or_(*filtr))).unique().scalars().all()
  
  
  def commit_to_database():
      """A shared function to make a commit to the database and
         handle exceptions if encountered"""
      dbLogger.info('Committing changes to db...')
      try:
          db.session.commit()
      except AssertionError as err:
          db.session.rollback()
          abort(409, err)
      except (exc.IntegrityError) as err:
          db.session.rollback()
          abort(409, err.orig)
      except Exception as err:
          db.session.rollback()
          abort(500, err)
  
  
  def rollback_database():
      dbLogger.info('Rolling back db...')
      db.session.rollback()
  
  
  