insert a node to its table and sets its ID if it was not provided by the user.
(ctx context.Context, insert *sql.InsertBuilder)
| 1458 | |
| 1459 | // insert a node to its table and sets its ID if it was not provided by the user. |
| 1460 | func (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. |
| 1479 | func (c *creator) ensureConflict(insert *sql.InsertBuilder) { |
no test coverage detected