Provides an interface for identical sqlx.DB and sqlx.Tx methods.
sqlx-queryable provides the Queryable
interface which wraps identical sqlx.DB
and sqlx.Tx
methods. The interface can be used when a function performs a database query directly or under a transaction.
Requires Golang v1.18 or greater.
go get github.com/alexandermac/sqlx-queryable
import queryable "github.com/alexandermac/sqlx-queryable"
// `q` can be sqlx.DB or sqlx.Tx
func getRecords(q Queryable) ([]Record, error) {
var records []Record
err := q.Select(&records, "SELECT * FROM records")
if err != nil {
panic(err)
}
return records, nil
}
Licensed under the MIT license.
Alexander Mac