Here are the examples of the python api sqlalchemy.event.listen taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
140 Examples
3
View Complete Implementation : flask.py
Copyright MIT License
Author : airbrake
Copyright MIT License
Author : airbrake
def _sqla_instrument(app):
try:
sqla = app.extensions["sqlalchemy"]
except Exception: # pylint: disable=broad-except
return
from sqlalchemy import event # pylint: disable=import-outside-toplevel
engine = sqla.db.get_engine()
event.listen(engine, "before_cursor_execute", _sqla_before_cursor_execute)
event.listen(engine, "after_cursor_execute", _sqla_after_cursor_execute)
3
View Complete Implementation : event_behavior.py
Copyright Apache License 2.0
Author : airbnb
Copyright Apache License 2.0
Author : airbnb
def __init__(self, db_session):
self._db_session = db_session
self._subscribe_event = Event()
self._epoch = datetime.utcnow()
def handle_event(*_):
self._subscribe_event.set()
event.listen(EventModel, 'after_insert', handle_event)
3
View Complete Implementation : trace.py
Copyright Apache License 2.0
Author : census-instrumentation
Copyright Apache License 2.0
Author : census-instrumentation
def trace_engine(engine):
"""Register the event before cursor execute and after cursor execute
to the event listner of the engine.
"""
event.listen(engine, 'before_cursor_execute', _before_cursor_execute)
event.listen(engine, 'after_cursor_execute', _after_cursor_execute)
3
View Complete Implementation : audit_log.py
Copyright GNU Affero General Public License v3.0
Author : CERT-Polska
Copyright GNU Affero General Public License v3.0
Author : CERT-Polska
def __init__(self, db_session):
event.listen(Base, 'after_insert', self.insert_listener, propagate=True)
event.listen(Base, 'after_update', self.update_listener, propagate=True)
event.listen(Base, 'after_delete', self.delete_listener, propagate=True)
event.listen(db_session, 'after_commit', self.action_after_commit)
self.state = AuditLogThreadLocalState()
3
View Complete Implementation : file_service.py
Copyright MIT License
Author : Floens
Copyright MIT License
Author : Floens
def init(_upload_queue_path, _cdn):
global upload_queue_path, cdn
upload_queue_path = _upload_queue_path
cdn = _cdn
# Register on the event when a post row is deleted to also remove it from the cdn
listen(FileOrmModel, 'after_delete', _on_file_deleted)
3
View Complete Implementation : sqlalchemy.py
Copyright BSD 2-Clause "Simplified" License
Author : getsentry
Copyright BSD 2-Clause "Simplified" License
Author : getsentry
@staticmethod
def setup_once():
# type: () -> None
listen(Engine, "before_cursor_execute", _before_cursor_execute)
listen(Engine, "after_cursor_execute", _after_cursor_execute)
listen(Engine, "dbapi_error", _dbapi_error)
3
View Complete Implementation : query.py
Copyright MIT License
Author : itsolutionsfactory
Copyright MIT License
Author : itsolutionsfactory
def __init__(self, *args, **kwargs):
super(BaseQuery, self).__init__(*args, **kwargs)
event.listen(
self, "before_compile", self._apply_backref_collection_limit, retval=True
)
VISITED_QUERIES.add(self)
3
View Complete Implementation : __init__.py
Copyright MIT License
Author : jpush
Copyright MIT License
Author : jpush
@clastmethod
def register(cls, session):
if not hasattr(session, '_model_changes'):
session._model_changes = {}
event.listen(session, 'before_flush', cls.record_ops)
event.listen(session, 'before_commit', cls.record_ops)
event.listen(session, 'before_commit', cls.before_commit)
event.listen(session, 'after_commit', cls.after_commit)
event.listen(session, 'after_rollback', cls.after_rollback)
3
View Complete Implementation : search.py
Copyright Mozilla Public License 2.0
Author : mozilla
Copyright Mozilla Public License 2.0
Author : mozilla
def __init__(self, config=None, session=None, whoosh_base=None):
self.config = config
self.session = session
self.mappings = []
event.listen(session, "after_flush", self._after_flush)
if not whoosh_base and config:
whoosh_base = config.get("WHOOSH_BASE")
if not whoosh_base:
whoosh_base = "whoosh_indexes" # Default value
self.whoosh_base = whoosh_base
self.indexes = {}
3
View Complete Implementation : db.py
Copyright MIT License
Author : MrKiven
Copyright MIT License
Author : MrKiven
@clastmethod
def create_engine(cls, *args, **kwds):
engine = patch_engine(sqlalchemy_create_engine(*args, **kwds))
event.listen(engine, 'before_cursor_execute', sql_commenter,
retval=True)
return engine