Database instrumentation

    The wrappers are modeled after middleware —they are callables which take another callable as one of their arguments. Theycall that callable to invoke the (possibly wrapped) database query, and theycan do what they want around that call. They are, however, created andinstalled by user code, and so don't need a separate factory like middleware do.

    Installing a wrapper is done in a context manager — so the wrappers aretemporary and specific to some flow in your code.

    And it would be used in a view to block queries from the template like so:

    The parameters sent to the wrappers are:

    • — a callable, which should be invoked with the rest of theparameters in order to execute the query.
    • params — a list/tuple of parameter values for the SQL command, or alist/tuple of lists/tuples if the wrapped call is executemany().
    • many — a indicating whether the ultimately invoked call isexecute() or executemany() (and whether params is expected to bea sequence of values, or a sequence of sequences of values).

    To use this, you would create a logger object and install it as a wrapper:

    • executewrapper(_wrapper)
    • Returns a context manager which, when entered, installs a wrapper arounddatabase query executions, and when exited, removes the wrapper. The wrapper isinstalled on the thread-local connection object.

    is a callable taking five arguments. It is called for every queryexecution in the scope of the context manager, with arguments execute,sql, params, many, and context as described above. It'sexpected to call and return the returnvalue of that call.