adding NopTx helper to dialect

Reviewed By: a8m

Differential Revision: D16757886

fbshipit-source-id: bd50ed4eefd30b5ed617220e6ba5b65b66cad2f3
This commit is contained in:
Alex Snast
2019-08-11 10:33:40 -07:00
committed by Facebook Github Bot
parent f2411742ae
commit ad53473dd7
2 changed files with 15 additions and 8 deletions

View File

@@ -44,6 +44,19 @@ type Tx interface {
driver.Tx
}
type nopTx struct {
Driver
}
func (nopTx) Commit() error { return nil }
func (nopTx) Rollback() error { return nil }
// NopTx returns a Tx with a no-op Commit / Rollback methods wrapping
// the provided Driver d.
func NopTx(d Driver) Tx {
return nopTx{d}
}
// DebugDriver is a driver that logs all driver operations.
type DebugDriver struct {
Driver // underlying driver.

View File

@@ -46,15 +46,9 @@ func (c *Driver) Query(ctx context.Context, query string, args, v interface{}) e
}
// Close is a nop close call. It should close the connection in case of WS client.
func (c *Driver) Close() error { return nil }
func (Driver) Close() error { return nil }
// Tx returns a nop transaction.
func (c *Driver) Tx(context.Context) (dialect.Tx, error) { return c, nil }
// Commit is a nop commit.
func (c *Driver) Commit() error { return nil }
// Rollback is a nop rollback.
func (c *Driver) Rollback() error { return nil }
func (c *Driver) Tx(context.Context) (dialect.Tx, error) { return dialect.NopTx(c), nil }
var _ dialect.Driver = (*Driver)(nil)