mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
@@ -81,14 +81,14 @@ func (nc *NodeCreate) Mutation() *NodeMutation {
|
||||
|
||||
// Save creates the Node in the database.
|
||||
func (nc *NodeCreate) Save(ctx context.Context) (*Node, error) {
|
||||
if err := nc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Node
|
||||
)
|
||||
if len(nc.hooks) == 0 {
|
||||
if err = nc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = nc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
@@ -96,6 +96,9 @@ func (nc *NodeCreate) Save(ctx context.Context) (*Node, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = nc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nc.mutation = mutation
|
||||
node, err = nc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
@@ -120,7 +123,8 @@ func (nc *NodeCreate) SaveX(ctx context.Context) *Node {
|
||||
return v
|
||||
}
|
||||
|
||||
func (nc *NodeCreate) preSave() error {
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (nc *NodeCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -212,13 +216,13 @@ func (ncb *NodeCreateBulk) Save(ctx context.Context) ([]*Node, error) {
|
||||
func(i int, root context.Context) {
|
||||
builder := ncb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*NodeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user