2023-04-20 10:28:54 +00:00
|
|
|
package sql
|
2023-03-13 19:06:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Driver = &SQLXDriver{}
|
|
|
|
|
|
|
|
// SQLXDriver driver, implements Driver
|
|
|
|
type SQLXDriver struct {
|
|
|
|
ctx context.Context
|
|
|
|
db *sqlx.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSQLXDriverFromPool returns a new sqlx driver for Postgres
|
2023-04-11 09:42:11 +00:00
|
|
|
func NewSQLXDriverFromPool(ctx context.Context, db *sqlx.DB) *SQLXDriver {
|
|
|
|
return &SQLXDriver{ctx: ctx, db: db}
|
2023-03-13 19:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryRow satisfies sql.Database
|
|
|
|
func (driver *SQLXDriver) QueryRow(_ context.Context, sql string, args ...interface{}) ScannableRow {
|
|
|
|
return driver.db.QueryRowx(sql, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec satisfies sql.Database
|
|
|
|
func (driver *SQLXDriver) Exec(_ context.Context, sql string, args ...interface{}) (Result, error) {
|
|
|
|
return driver.db.Exec(sql, args...)
|
|
|
|
}
|