MCPcopy
hub / github.com/ent/ent / mayTx

Method mayTx

dialect/sql/sqlgraph/graph.go:1589–1598  ·  view source on GitHub ↗

mayTx opens a new transaction if the create operation spans across multiple statements.

(ctx context.Context, drv dialect.Driver)

Source from the content-addressed store, hash-verified

1587
1588// mayTx opens a new transaction if the create operation spans across multiple statements.
1589func (c *batchCreator) mayTx(ctx context.Context, drv dialect.Driver) (dialect.Tx, error) {
1590 for _, node := range c.Nodes {
1591 for _, edge := range node.Edges {
1592 if isExternalEdge(edge) {
1593 return drv.Tx(ctx)
1594 }
1595 }
1596 }
1597 return dialect.NopTx(drv), nil
1598}
1599
1600// batchInsert inserts a batch of nodes to their table and sets their ID if it was not provided by the user.
1601func (c *batchCreator) batchInsert(ctx context.Context, tx dialect.ExecQuerier, insert *sql.InsertBuilder) error {

Callers 1

nodesMethod · 0.95

Calls 3

NopTxFunction · 0.92
isExternalEdgeFunction · 0.85
TxMethod · 0.65

Tested by

no test coverage detected