Conversation
| type Queryer interface { | ||
| Query(query string, args ...interface{}) (*sql.Rows, error) | ||
| Queryx(query string, args ...interface{}) (*Rows, error) | ||
| QueryRow(query string, args ...interface{}) *sql.Row |
There was a problem hiding this comment.
Note
Adding a missing method to this interface.
We have Query/Queryx, and QueryRowx, but this method was missing.
| type QueryerContext interface { | ||
| QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) | ||
| QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) | ||
| QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row |
There was a problem hiding this comment.
Note
Adding a missing method to this interface.
We have QueryContext/QueryxContext, and QueryRowxContext, but this method was missing.
| func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) { | ||
| return NamedQueryContext(ctx, tx, query, arg) | ||
| } |
There was a problem hiding this comment.
Note
This method exists on DB, but was missing from Tx.
This is the only query-related method I found that is needed to allow these two types to be used interchangeably.
|
I ran into this too! Totally agree, there should be a common interface. I ended up making one for the subset of methods that we use, but it can be easier. |
|
I need this too |
slashformotion
left a comment
There was a problem hiding this comment.
LGTM, we need this merged ASAP please.
Would be great to get this moving !
This PR adds some missing methods to flesh out interfaces and make
DBandTxhave more of a shared interface.This opens up the possibility of creating a common interface that represents either one so that functions can be written that execute queries without needing to know if they're being run within a transaction or not.
I wasn't sure how the tests were organized for this project. If there's a specific test function you'd like them added to (or a new one), let me know.
📌 Long-term (future PR), I'd like to create an interface (or a few) that represent the remaining shared query-related methods, and then one interface that represents either a
DBorTx. These are the additional methods not represented in another interface right now:Get(dest interface{}, query string, args ...interface{}) errorGetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) errorMustExec(query string, args ...interface{}) sql.ResultMustExecContext(ctx context.Context, query string, args ...interface{}) sql.ResultNamedExec(query string, arg interface{}) (sql.Result, error)NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)PrepareNamed(query string) (*sqlx.NamedStmt, error)PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)Preparex(query string) (*sqlx.Stmt, error)PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)Select(dest interface{}, query string, args ...interface{}) errorSelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error