On Friday 15 September 2017 11:09:58 Anssi Kääriäinen wrote: > Would it make sense to use the same technique used for HTTP > request/response middleware? That is, the hook would look a bit like this: > > def simple_execute_hook(execute): > # One-time configuration and initialization. > def execute_hook(sql, params, many, context): > # Code to be executed for each cursor.execute() call. > # If many = True, the final call will be execute_many. > # The context parameter might contain stuff like used > # connection. > execute(sql, params, many, context) > # Code to be executed after the SQL has been ran. > return execute_hook > > You would then add the hook with the connection's context manager. > > The reason I'm asking is that this way the coding style would be > immediately familiar if you have used the request/response middlewares. >
That's an interesting suggestion. At first look, it seems a nicer API than the context manager. I'm a little worried about how errors would be handled, though.