mirror of
https://github.com/ent/ent.git
synced 2026-04-29 06:00:55 +03:00
dialect/sql/sqlgraph: allow setting stmt modifiers for create-one
This commit is contained in:
committed by
Ariel Mashraki
parent
19b418d1a0
commit
b9fcbff724
@@ -344,7 +344,20 @@ type (
|
||||
ID *FieldSpec
|
||||
Fields []*FieldSpec
|
||||
Edges []*EdgeSpec
|
||||
|
||||
// The Modifiers option allows providing custom functions to
|
||||
// modify the INSERT statement of the node before it is executed.
|
||||
//
|
||||
// sqlgraph.CreateSpec{
|
||||
// Modifiers: []func(*sql.InsertBuilder) {
|
||||
// OnConflictOptions(...),
|
||||
// ReturningOptions(...),
|
||||
// },
|
||||
// }
|
||||
//
|
||||
Modifiers []func(*sql.InsertBuilder)
|
||||
}
|
||||
|
||||
// BatchCreateSpec holds the information for creating
|
||||
// multiple nodes in the graph.
|
||||
BatchCreateSpec struct {
|
||||
@@ -958,6 +971,9 @@ func (c *creator) insert(ctx context.Context, tx dialect.ExecQuerier, insert *sq
|
||||
query, args := insert.Query()
|
||||
return tx.Exec(ctx, query, args, &res)
|
||||
}
|
||||
for _, m := range c.CreateSpec.Modifiers {
|
||||
m(insert)
|
||||
}
|
||||
id, err := insertLastID(ctx, tx, insert.Returning(c.ID.Column))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user