// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/linepoint" "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // LinePointCreate is the builder for creating a LinePoint entity. type LinePointCreate struct { config mutation *LinePointMutation hooks []Hook } // SetPointType sets the "pointType" field. func (_c *LinePointCreate) SetPointType(v string) *LinePointCreate { _c.mutation.SetPointType(v) return _c } // SetPointNo sets the "pointNo" field. func (_c *LinePointCreate) SetPointNo(v string) *LinePointCreate { _c.mutation.SetPointNo(v) return _c } // SetLabel sets the "label" field. func (_c *LinePointCreate) SetLabel(v string) *LinePointCreate { _c.mutation.SetLabel(v) return _c } // SetNillableLabel sets the "label" field if the given value is not nil. func (_c *LinePointCreate) SetNillableLabel(v *string) *LinePointCreate { if v != nil { _c.SetLabel(*v) } return _c } // SetSeq sets the "seq" field. func (_c *LinePointCreate) SetSeq(v int) *LinePointCreate { _c.mutation.SetSeq(v) return _c } // SetNillableSeq sets the "seq" field if the given value is not nil. func (_c *LinePointCreate) SetNillableSeq(v *int) *LinePointCreate { if v != nil { _c.SetSeq(*v) } return _c } // SetStationNo sets the "stationNo" field. func (_c *LinePointCreate) SetStationNo(v int) *LinePointCreate { _c.mutation.SetStationNo(v) return _c } // SetNillableStationNo sets the "stationNo" field if the given value is not nil. func (_c *LinePointCreate) SetNillableStationNo(v *int) *LinePointCreate { if v != nil { _c.SetStationNo(*v) } return _c } // SetCurrentSn sets the "currentSn" field. func (_c *LinePointCreate) SetCurrentSn(v string) *LinePointCreate { _c.mutation.SetCurrentSn(v) return _c } // SetNillableCurrentSn sets the "currentSn" field if the given value is not nil. func (_c *LinePointCreate) SetNillableCurrentSn(v *string) *LinePointCreate { if v != nil { _c.SetCurrentSn(*v) } return _c } // SetOrderNo sets the "orderNo" field. func (_c *LinePointCreate) SetOrderNo(v string) *LinePointCreate { _c.mutation.SetOrderNo(v) return _c } // SetNillableOrderNo sets the "orderNo" field if the given value is not nil. func (_c *LinePointCreate) SetNillableOrderNo(v *string) *LinePointCreate { if v != nil { _c.SetOrderNo(*v) } return _c } // SetOccupied sets the "occupied" field. func (_c *LinePointCreate) SetOccupied(v bool) *LinePointCreate { _c.mutation.SetOccupied(v) return _c } // SetNillableOccupied sets the "occupied" field if the given value is not nil. func (_c *LinePointCreate) SetNillableOccupied(v *bool) *LinePointCreate { if v != nil { _c.SetOccupied(*v) } return _c } // SetUpdatedAt sets the "updatedAt" field. func (_c *LinePointCreate) SetUpdatedAt(v time.Time) *LinePointCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil. func (_c *LinePointCreate) SetNillableUpdatedAt(v *time.Time) *LinePointCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *LinePointCreate) SetID(v int) *LinePointCreate { _c.mutation.SetID(v) return _c } // Mutation returns the LinePointMutation object of the builder. func (_c *LinePointCreate) Mutation() *LinePointMutation { return _c.mutation } // Save creates the LinePoint in the database. func (_c *LinePointCreate) Save(ctx context.Context) (*LinePoint, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *LinePointCreate) SaveX(ctx context.Context) *LinePoint { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *LinePointCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *LinePointCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_c *LinePointCreate) defaults() { if _, ok := _c.mutation.Label(); !ok { v := linepoint.DefaultLabel _c.mutation.SetLabel(v) } if _, ok := _c.mutation.Seq(); !ok { v := linepoint.DefaultSeq _c.mutation.SetSeq(v) } if _, ok := _c.mutation.StationNo(); !ok { v := linepoint.DefaultStationNo _c.mutation.SetStationNo(v) } if _, ok := _c.mutation.CurrentSn(); !ok { v := linepoint.DefaultCurrentSn _c.mutation.SetCurrentSn(v) } if _, ok := _c.mutation.OrderNo(); !ok { v := linepoint.DefaultOrderNo _c.mutation.SetOrderNo(v) } if _, ok := _c.mutation.Occupied(); !ok { v := linepoint.DefaultOccupied _c.mutation.SetOccupied(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := linepoint.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *LinePointCreate) check() error { if _, ok := _c.mutation.PointType(); !ok { return &ValidationError{Name: "pointType", err: errors.New(`ent: missing required field "LinePoint.pointType"`)} } if v, ok := _c.mutation.PointType(); ok { if err := linepoint.PointTypeValidator(v); err != nil { return &ValidationError{Name: "pointType", err: fmt.Errorf(`ent: validator failed for field "LinePoint.pointType": %w`, err)} } } if _, ok := _c.mutation.PointNo(); !ok { return &ValidationError{Name: "pointNo", err: errors.New(`ent: missing required field "LinePoint.pointNo"`)} } if v, ok := _c.mutation.PointNo(); ok { if err := linepoint.PointNoValidator(v); err != nil { return &ValidationError{Name: "pointNo", err: fmt.Errorf(`ent: validator failed for field "LinePoint.pointNo": %w`, err)} } } if _, ok := _c.mutation.Label(); !ok { return &ValidationError{Name: "label", err: errors.New(`ent: missing required field "LinePoint.label"`)} } if v, ok := _c.mutation.Label(); ok { if err := linepoint.LabelValidator(v); err != nil { return &ValidationError{Name: "label", err: fmt.Errorf(`ent: validator failed for field "LinePoint.label": %w`, err)} } } if _, ok := _c.mutation.Seq(); !ok { return &ValidationError{Name: "seq", err: errors.New(`ent: missing required field "LinePoint.seq"`)} } if _, ok := _c.mutation.StationNo(); !ok { return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "LinePoint.stationNo"`)} } if _, ok := _c.mutation.CurrentSn(); !ok { return &ValidationError{Name: "currentSn", err: errors.New(`ent: missing required field "LinePoint.currentSn"`)} } if v, ok := _c.mutation.CurrentSn(); ok { if err := linepoint.CurrentSnValidator(v); err != nil { return &ValidationError{Name: "currentSn", err: fmt.Errorf(`ent: validator failed for field "LinePoint.currentSn": %w`, err)} } } if _, ok := _c.mutation.OrderNo(); !ok { return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "LinePoint.orderNo"`)} } if v, ok := _c.mutation.OrderNo(); ok { if err := linepoint.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "LinePoint.orderNo": %w`, err)} } } if _, ok := _c.mutation.Occupied(); !ok { return &ValidationError{Name: "occupied", err: errors.New(`ent: missing required field "LinePoint.occupied"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updatedAt", err: errors.New(`ent: missing required field "LinePoint.updatedAt"`)} } if v, ok := _c.mutation.ID(); ok { if err := linepoint.IDValidator(v); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "LinePoint.id": %w`, err)} } } return nil } func (_c *LinePointCreate) sqlSave(ctx context.Context) (*LinePoint, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != _node.ID { id := _spec.ID.Value.(int64) _node.ID = int(id) } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *LinePointCreate) createSpec() (*LinePoint, *sqlgraph.CreateSpec) { var ( _node = &LinePoint{config: _c.config} _spec = sqlgraph.NewCreateSpec(linepoint.Table, sqlgraph.NewFieldSpec(linepoint.FieldID, field.TypeInt)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := _c.mutation.PointType(); ok { _spec.SetField(linepoint.FieldPointType, field.TypeString, value) _node.PointType = value } if value, ok := _c.mutation.PointNo(); ok { _spec.SetField(linepoint.FieldPointNo, field.TypeString, value) _node.PointNo = value } if value, ok := _c.mutation.Label(); ok { _spec.SetField(linepoint.FieldLabel, field.TypeString, value) _node.Label = value } if value, ok := _c.mutation.Seq(); ok { _spec.SetField(linepoint.FieldSeq, field.TypeInt, value) _node.Seq = value } if value, ok := _c.mutation.StationNo(); ok { _spec.SetField(linepoint.FieldStationNo, field.TypeInt, value) _node.StationNo = value } if value, ok := _c.mutation.CurrentSn(); ok { _spec.SetField(linepoint.FieldCurrentSn, field.TypeString, value) _node.CurrentSn = value } if value, ok := _c.mutation.OrderNo(); ok { _spec.SetField(linepoint.FieldOrderNo, field.TypeString, value) _node.OrderNo = value } if value, ok := _c.mutation.Occupied(); ok { _spec.SetField(linepoint.FieldOccupied, field.TypeBool, value) _node.Occupied = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(linepoint.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } return _node, _spec } // LinePointCreateBulk is the builder for creating many LinePoint entities in bulk. type LinePointCreateBulk struct { config err error builders []*LinePointCreate } // Save creates the LinePoint entities in the database. func (_c *LinePointCreateBulk) Save(ctx context.Context) ([]*LinePoint, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*LinePoint, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*LinePointMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.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, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) nodes[i].ID = int(id) } mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *LinePointCreateBulk) SaveX(ctx context.Context) []*LinePoint { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *LinePointCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *LinePointCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } }