|
|
|
|
@ -20,8 +20,8 @@ import (
|
|
|
|
|
"github.com/dexidp/dex/storage/ent/db/password" |
|
|
|
|
"github.com/dexidp/dex/storage/ent/db/refreshtoken" |
|
|
|
|
|
|
|
|
|
"github.com/facebook/ent/dialect" |
|
|
|
|
"github.com/facebook/ent/dialect/sql" |
|
|
|
|
"entgo.io/ent/dialect" |
|
|
|
|
"entgo.io/ent/dialect/sql" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Client is the client that holds all ent builders.
|
|
|
|
|
@ -98,9 +98,10 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|
|
|
|
} |
|
|
|
|
tx, err := newTx(ctx, c.driver) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("db: starting a transaction: %v", err) |
|
|
|
|
return nil, fmt.Errorf("db: starting a transaction: %w", err) |
|
|
|
|
} |
|
|
|
|
cfg := config{driver: tx, log: c.log, debug: c.debug, hooks: c.hooks} |
|
|
|
|
cfg := c.config |
|
|
|
|
cfg.driver = tx |
|
|
|
|
return &Tx{ |
|
|
|
|
ctx: ctx, |
|
|
|
|
config: cfg, |
|
|
|
|
@ -122,11 +123,14 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|
|
|
|
if _, ok := c.driver.(*txDriver); ok { |
|
|
|
|
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") |
|
|
|
|
} |
|
|
|
|
tx, err := c.driver.(*sql.Driver).BeginTx(ctx, opts) |
|
|
|
|
tx, err := c.driver.(interface { |
|
|
|
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) |
|
|
|
|
}).BeginTx(ctx, opts) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("ent: starting a transaction: %v", err) |
|
|
|
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err) |
|
|
|
|
} |
|
|
|
|
cfg := config{driver: &txDriver{tx: tx, drv: c.driver}, log: c.log, debug: c.debug, hooks: c.hooks} |
|
|
|
|
cfg := c.config |
|
|
|
|
cfg.driver = &txDriver{tx: tx, drv: c.driver} |
|
|
|
|
return &Tx{ |
|
|
|
|
config: cfg, |
|
|
|
|
AuthCode: NewAuthCodeClient(cfg), |
|
|
|
|
@ -153,7 +157,8 @@ func (c *Client) Debug() *Client {
|
|
|
|
|
if c.debug { |
|
|
|
|
return c |
|
|
|
|
} |
|
|
|
|
cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true, hooks: c.hooks} |
|
|
|
|
cfg := c.config |
|
|
|
|
cfg.driver = dialect.Debug(c.driver, c.log) |
|
|
|
|
client := &Client{config: cfg} |
|
|
|
|
client.init() |
|
|
|
|
return client |
|
|
|
|
|