mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-29 08:18:27 +00:00
ff65f0ec7b
This reverts commit3cebd8dbfb
, reversing changes made toed4b3a58a7
.
28 lines
685 B
Go
28 lines
685 B
Go
package sqlutil
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
// DummyWriter implements sqlutil.Writer.
|
|
// The DummyWriter is designed to allow reuse of the sqlutil.Writer
|
|
// interface but, unlike ExclusiveWriter, it will not guarantee
|
|
// writer exclusivity. This is fine in PostgreSQL where overlapping
|
|
// transactions and writes are acceptable.
|
|
type DummyWriter struct {
|
|
}
|
|
|
|
// NewDummyWriter returns a new dummy writer.
|
|
func NewDummyWriter() Writer {
|
|
return &DummyWriter{}
|
|
}
|
|
|
|
func (w *DummyWriter) Do(db *sql.DB, txn *sql.Tx, f func(txn *sql.Tx) error) error {
|
|
if db != nil && txn == nil {
|
|
return WithTransaction(db, func(txn *sql.Tx) error {
|
|
return f(txn)
|
|
})
|
|
} else {
|
|
return f(txn)
|
|
}
|
|
}
|