mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
adding NopTx helper to dialect
Reviewed By: a8m Differential Revision: D16757886 fbshipit-source-id: bd50ed4eefd30b5ed617220e6ba5b65b66cad2f3
This commit is contained in:
committed by
Facebook Github Bot
parent
f2411742ae
commit
ad53473dd7
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user