Debian Codegraph @

ent/gql_transaction.go

raw
1 // Code generated by ent, DO NOT EDIT.
2
3 package ent
4
5 import (
6 "context"
7 "database/sql/driver"
8 "errors"
9 )
10
11 // OpenTx opens a transaction and returns a transactional
12 // context along with the created transaction.
13 func (c *Client) OpenTx(ctx context.Context) (context.Context, driver.Tx, error) {
14 tx, err := c.Tx(ctx)
15 if err != nil {
16 return nil, nil, err
17 }
18 ctx = NewTxContext(ctx, tx)
19 ctx = NewContext(ctx, tx.Client())
20 return ctx, tx, nil
21 }
22
23 // OpenTxFromContext open transactions from client stored in context.
24 func OpenTxFromContext(ctx context.Context) (context.Context, driver.Tx, error) {
25 client := FromContext(ctx)
26 if client == nil {
27 return nil, nil, errors.New("no client attached to context")
28 }
29 return client.OpenTx(ctx)
30 }