diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-18 00:12:12 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-18 00:12:12 +0000 |
commit | 793339505569fe5e69ad4c9a70071406aa11a09e (patch) | |
tree | 778bd0e277d8ba6a411a648e480030b77d02795c /lib/sqlalchemy/interfaces.py | |
parent | 6a99f293130c6e11aba28c19c84f9195c5bf60c7 (diff) | |
download | sqlalchemy-793339505569fe5e69ad4c9a70071406aa11a09e.tar.gz |
document ConnectionProxy
Diffstat (limited to 'lib/sqlalchemy/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/interfaces.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py index f9c21d246..dfceffe44 100644 --- a/lib/sqlalchemy/interfaces.py +++ b/lib/sqlalchemy/interfaces.py @@ -108,20 +108,37 @@ class PoolListener(object): class ConnectionProxy(object): """Allows interception of statement execution by Connections. - Subclass ``ConnectionProxy``, overriding either or both of - ``execute()`` and ``cursor_execute()`` The default behavior is provided, - which is to call the given executor function with the remaining - arguments. The proxy is then connected to an engine via - ``create_engine(url, proxy=MyProxy())`` where ``MyProxy`` is - the user-defined ``ConnectionProxy`` class. + Either or both of the ``execute()`` and ``cursor_execute()`` + may be implemented to intercept compiled statement and + cursor level executions, e.g.:: + + class MyProxy(ConnectionProxy): + def execute(self, conn, execute, clauseelement, *multiparams, **params): + print "compiled statement:", clauseelement + return execute(clauseelement, *multiparams, **params) + + def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): + print "raw statement:", statement + return execute(cursor, statement, parameters, context) + + The ``execute`` argument is a function that will fulfill the default + execution behavior for the operation. The signature illustrated + in the example should be used. + + The proxy is installed into an :class:`~sqlalchemy.engine.Engine` via + the ``proxy`` argument:: + + e = create_engine('someurl://', proxy=MyProxy()) """ def execute(self, conn, execute, clauseelement, *multiparams, **params): - """""" + """Intercept high level execute() events.""" + return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): - """""" + """Intercept low-level cursor execute() events.""" + return execute(cursor, statement, parameters, context) |