-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stmt: export WrappedParentStmt to allow Stmt wrapping in interceptors #16
Conversation
In some scenarios it is required to annotate Stmt, Rows and Tx objects with additional data in an interceptor. Usecases can be: - relating a PrepareContext() call with operations on the Stmt in traces, - forwarding the query string passed to PrepareContext() to methods of the Stmt For Rows and Tx objects it is possible in an interceptor by creating a struct that wraps the original objects and has additional user-defined fields. The user-wrapped object is passed to the RowsNext, RowsClose, TxCommit and TxRollback interceptor methods. In those a type-conversion can be done and the user-defined data accessed. For Stmt objects this worked only for the StmtClose call. When the StmtQueryContext StmtExecContext methods of the interceptor were called, the driver.Stmt that was passed as parameter was wrapped into the private wrappedStmt struct by sqlmw. Because it was private, an interceptor implementation could not convert the Stmt parameter type and access it's own wrapped Stmt. This commit allows also to wrap Stmts in an interceptor and annotate it with additional data. This is done by making WrappedParentStmt public and changing the interceptor interface to pass stmt of this type. Additionally: - wrappedParentStmt is renamed to Stmt, - a Stmt.Parent() helper method is added, - a testcase and example is added
7d6add2
to
db08673
Compare
@tcolgate fyi, I gave up on getting my PRs merged here and created a fork: https://github.com/simplesurance/sqlmw |
I don't have a tonne of time. My first thought though is that, since we employed the Unwrap approach in my Rows PR, would it make sense for this PR to follow that lead? |
Yes, would be best to have a consistent approach. The difference between Rows and Stmts is that when the rows Interceptor methods ( Am I misunderstanding something? Or do you see a way how Stmts could be refactored to use the same approach then for rows? |
This resolves #10