@@ -75,11 +75,17 @@ func (cc *ConnectorCreate) Save(ctx context.Context) (*Connector, error) {
|
||||
return nil, err
|
||||
}
|
||||
cc.mutation = mutation
|
||||
node, err = cc.sqlSave(ctx)
|
||||
if node, err = cc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(cc.hooks) - 1; i >= 0; i-- {
|
||||
if cc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)")
|
||||
}
|
||||
mut = cc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cc.mutation); err != nil {
|
||||
@@ -98,33 +104,46 @@ func (cc *ConnectorCreate) SaveX(ctx context.Context) *Connector {
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cc *ConnectorCreate) Exec(ctx context.Context) error {
|
||||
_, err := cc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cc *ConnectorCreate) ExecX(ctx context.Context) {
|
||||
if err := cc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cc *ConnectorCreate) check() error {
|
||||
if _, ok := cc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New("db: missing required field \"type\"")}
|
||||
return &ValidationError{Name: "type", err: errors.New(`db: missing required field "type"`)}
|
||||
}
|
||||
if v, ok := cc.mutation.GetType(); ok {
|
||||
if err := connector.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf("db: validator failed for field \"type\": %w", err)}
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := cc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New("db: missing required field \"name\"")}
|
||||
return &ValidationError{Name: "name", err: errors.New(`db: missing required field "name"`)}
|
||||
}
|
||||
if v, ok := cc.mutation.Name(); ok {
|
||||
if err := connector.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf("db: validator failed for field \"name\": %w", err)}
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := cc.mutation.ResourceVersion(); !ok {
|
||||
return &ValidationError{Name: "resource_version", err: errors.New("db: missing required field \"resource_version\"")}
|
||||
return &ValidationError{Name: "resource_version", err: errors.New(`db: missing required field "resource_version"`)}
|
||||
}
|
||||
if _, ok := cc.mutation.Config(); !ok {
|
||||
return &ValidationError{Name: "config", err: errors.New("db: missing required field \"config\"")}
|
||||
return &ValidationError{Name: "config", err: errors.New(`db: missing required field "config"`)}
|
||||
}
|
||||
if v, ok := cc.mutation.ID(); ok {
|
||||
if err := connector.IDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "id", err: fmt.Errorf("db: validator failed for field \"id\": %w", err)}
|
||||
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -133,8 +152,8 @@ func (cc *ConnectorCreate) check() error {
|
||||
func (cc *ConnectorCreate) sqlSave(ctx context.Context) (*Connector, error) {
|
||||
_node, _spec := cc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -219,17 +238,19 @@ func (ccb *ConnectorCreateBulk) Save(ctx context.Context) ([]*Connector, error)
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ccb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
@@ -254,3 +275,16 @@ func (ccb *ConnectorCreateBulk) SaveX(ctx context.Context) []*Connector {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ccb *ConnectorCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := ccb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ccb *ConnectorCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := ccb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user