mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
* fix grammar and english usage in templates * bindata gen * codegen * go generate ./again...
26 lines
886 B
Cheetah
26 lines
886 B
Cheetah
{{/*
|
|
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 specified 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 }}
|