Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/balancer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ type tx struct {
cfn CloseFunc
}

func (tx *tx) Driver() string { return sql.DriverOf(tx.Tx) }

func (tx *tx) Commit() error {
err := tx.Tx.Commit()

Expand Down
1 change: 1 addition & 0 deletions backend/postgres/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type tx struct {

func (tx *tx) Commit() error { return wrapErr(tx.tx.Commit()) }
func (tx *tx) Rollback() error { return wrapErr(tx.tx.Rollback()) }
func (tx *tx) Driver() string { return sql.DriverOf(tx.tx) }

type queryer struct {
q sql.Queryer
Expand Down
13 changes: 9 additions & 4 deletions backend/simple/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ type tx struct {

q *queryer
tx *stdsql.Tx

driver string
}

func (tx *tx) Driver() string { return tx.driver }

func (tx *tx) Commit() error {
select {
case <-tx.ctx.Done():
Expand Down Expand Up @@ -160,9 +164,10 @@ func (d *db) BeginTx(ctx context.Context, opts sql.TxOptions) (sql.Tx, error) {
}

return &tx{
ctx: ctx,
ch: make(chan struct{}, 1),
q: &queryer{t},
tx: t,
ctx: ctx,
ch: make(chan struct{}, 1),
q: &queryer{t},
tx: t,
driver: d.driver,
}, nil
}
1 change: 1 addition & 0 deletions backend/sqlite3/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type tx struct {

func (tx *tx) Commit() error { return wrapErr(tx.tx.Commit()) }
func (tx *tx) Rollback() error { return wrapErr(tx.tx.Rollback()) }
func (tx *tx) Driver() string { return sql.DriverOf(tx.tx) }

func (db *db) Driver() string { return db.db.Driver() }

Expand Down
1 change: 1 addition & 0 deletions backend/static/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Tx struct {

func (tx *Tx) Commit() error { return tx.CommitErr }
func (tx *Tx) Rollback() error { return tx.RollbackErr }
func (tx *Tx) Driver() string { return "sqltest" }

func (db *DB) Driver() string { return "sqltest" }

Expand Down
10 changes: 10 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ type DB interface {
Driver() string
}

// DriverOf returns the driver of q, the DBs and the transactions they
// begin expose it. It returns an empty string when q does not.
func DriverOf(q Queryer) string {
if d, ok := q.(interface{ Driver() string }); ok {
return d.Driver()
}

return ""
}

type TxOptions struct {
Isolation IsolationLevel
}
Expand Down
Loading
Loading