MCPcopy Index your code
hub / github.com/ent/ent / insert

Method insert

dialect/sql/sqlgraph/graph.go:1460–1476  ·  view source on GitHub ↗

insert a node to its table and sets its ID if it was not provided by the user.

(ctx context.Context, insert *sql.InsertBuilder)

Source from the content-addressed store, hash-verified

1458
1459// insert a node to its table and sets its ID if it was not provided by the user.
1460func (c *creator) insert(ctx context.Context, insert *sql.InsertBuilder) error {
1461 c.ensureConflict(insert)
1462 // If the id field was provided by the user.
1463 if c.ID.Value != nil {
1464 insert.Set(c.ID.Column, c.ID.Value)
1465 // In case of "ON CONFLICT", the record may exist in the
1466 // database, and we need to get back the database id field.
1467 if len(c.CreateSpec.OnConflict) == 0 {
1468 query, args, err := insert.QueryErr()
1469 if err != nil {
1470 return err
1471 }
1472 return c.tx.Exec(ctx, query, args, nil)
1473 }
1474 }
1475 return c.insertLastID(ctx, insert.Returning(c.ID.Column))
1476}
1477
1478// ensureConflict ensures the ON CONFLICT is added to the insert statement.
1479func (c *creator) ensureConflict(insert *sql.InsertBuilder) {

Callers 1

nodeMethod · 0.95

Calls 6

ensureConflictMethod · 0.95
insertLastIDMethod · 0.95
QueryErrMethod · 0.80
ExecMethod · 0.65
SetMethod · 0.45
ReturningMethod · 0.45

Tested by

no test coverage detected