{{/* Copyright 2019-present Facebook Inc. All rights reserved. This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree. */}} {{ define "dialect/sql/txoptions" }} // BeginTx returns a transactional client with options. 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) if err != nil { return nil, fmt.Errorf("ent: starting a transaction: %v", err) } cfg := config{driver: &txDriver{tx: tx, drv: c.driver}, log: c.log, debug: c.debug, hooks: c.hooks} return &Tx{ config: cfg, {{ range $_, $n := $.Nodes -}} {{ $n.Name }}: New{{ $n.Name }}Client(cfg), {{ end -}} }, nil } {{ end }}