代码拉取完成,页面将自动刷新
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/devicekpi"
)
// DeviceKpiCreate is the builder for creating a DeviceKpi entity.
type DeviceKpiCreate struct {
config
mutation *DeviceKpiMutation
hooks []Hook
Table string
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (dkc *DeviceKpiCreate) SetCreatedAt(t time.Time) *DeviceKpiCreate {
dkc.mutation.SetCreatedAt(t)
return dkc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableCreatedAt(t *time.Time) *DeviceKpiCreate {
if t != nil {
dkc.SetCreatedAt(*t)
}
return dkc
}
// SetUpdatedAt sets the "updated_at" field.
func (dkc *DeviceKpiCreate) SetUpdatedAt(t time.Time) *DeviceKpiCreate {
dkc.mutation.SetUpdatedAt(t)
return dkc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableUpdatedAt(t *time.Time) *DeviceKpiCreate {
if t != nil {
dkc.SetUpdatedAt(*t)
}
return dkc
}
// SetStatus sets the "status" field.
func (dkc *DeviceKpiCreate) SetStatus(u uint8) *DeviceKpiCreate {
dkc.mutation.SetStatus(u)
return dkc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableStatus(u *uint8) *DeviceKpiCreate {
if u != nil {
dkc.SetStatus(*u)
}
return dkc
}
// SetSort sets the "sort" field.
func (dkc *DeviceKpiCreate) SetSort(u uint32) *DeviceKpiCreate {
dkc.mutation.SetSort(u)
return dkc
}
// SetNillableSort sets the "sort" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableSort(u *uint32) *DeviceKpiCreate {
if u != nil {
dkc.SetSort(*u)
}
return dkc
}
// SetIotID sets the "iotID" field.
func (dkc *DeviceKpiCreate) SetIotID(s string) *DeviceKpiCreate {
dkc.mutation.SetIotID(s)
return dkc
}
// SetDeviceName sets the "deviceName" field.
func (dkc *DeviceKpiCreate) SetDeviceName(s string) *DeviceKpiCreate {
dkc.mutation.SetDeviceName(s)
return dkc
}
// SetProductKey sets the "productKey" field.
func (dkc *DeviceKpiCreate) SetProductKey(s string) *DeviceKpiCreate {
dkc.mutation.SetProductKey(s)
return dkc
}
// SetKpi sets the "kpi" field.
func (dkc *DeviceKpiCreate) SetKpi(f float64) *DeviceKpiCreate {
dkc.mutation.SetKpi(f)
return dkc
}
// SetNillableKpi sets the "kpi" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableKpi(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetKpi(*f)
}
return dkc
}
// SetX sets the "x" field.
func (dkc *DeviceKpiCreate) SetX(f float64) *DeviceKpiCreate {
dkc.mutation.SetX(f)
return dkc
}
// SetNillableX sets the "x" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableX(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetX(*f)
}
return dkc
}
// SetY sets the "y" field.
func (dkc *DeviceKpiCreate) SetY(f float64) *DeviceKpiCreate {
dkc.mutation.SetY(f)
return dkc
}
// SetNillableY sets the "y" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableY(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetY(*f)
}
return dkc
}
// SetA sets the "a" field.
func (dkc *DeviceKpiCreate) SetA(f float64) *DeviceKpiCreate {
dkc.mutation.SetA(f)
return dkc
}
// SetNillableA sets the "a" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableA(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetA(*f)
}
return dkc
}
// SetB sets the "b" field.
func (dkc *DeviceKpiCreate) SetB(f float64) *DeviceKpiCreate {
dkc.mutation.SetB(f)
return dkc
}
// SetNillableB sets the "b" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableB(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetB(*f)
}
return dkc
}
// SetWeekKpi sets the "weekKpi" field.
func (dkc *DeviceKpiCreate) SetWeekKpi(f float64) *DeviceKpiCreate {
dkc.mutation.SetWeekKpi(f)
return dkc
}
// SetNillableWeekKpi sets the "weekKpi" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableWeekKpi(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetWeekKpi(*f)
}
return dkc
}
// SetMonthKpi sets the "monthKpi" field.
func (dkc *DeviceKpiCreate) SetMonthKpi(f float64) *DeviceKpiCreate {
dkc.mutation.SetMonthKpi(f)
return dkc
}
// SetNillableMonthKpi sets the "monthKpi" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableMonthKpi(f *float64) *DeviceKpiCreate {
if f != nil {
dkc.SetMonthKpi(*f)
}
return dkc
}
// SetCurrentDay1 sets the "currentDay1" field.
func (dkc *DeviceKpiCreate) SetCurrentDay1(i int64) *DeviceKpiCreate {
dkc.mutation.SetCurrentDay1(i)
return dkc
}
// SetNillableCurrentDay1 sets the "currentDay1" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableCurrentDay1(i *int64) *DeviceKpiCreate {
if i != nil {
dkc.SetCurrentDay1(*i)
}
return dkc
}
// SetCurrentDay7 sets the "currentDay7" field.
func (dkc *DeviceKpiCreate) SetCurrentDay7(i int64) *DeviceKpiCreate {
dkc.mutation.SetCurrentDay7(i)
return dkc
}
// SetNillableCurrentDay7 sets the "currentDay7" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableCurrentDay7(i *int64) *DeviceKpiCreate {
if i != nil {
dkc.SetCurrentDay7(*i)
}
return dkc
}
// SetCurrentDay28 sets the "currentDay28" field.
func (dkc *DeviceKpiCreate) SetCurrentDay28(i int64) *DeviceKpiCreate {
dkc.mutation.SetCurrentDay28(i)
return dkc
}
// SetNillableCurrentDay28 sets the "currentDay28" field if the given value is not nil.
func (dkc *DeviceKpiCreate) SetNillableCurrentDay28(i *int64) *DeviceKpiCreate {
if i != nil {
dkc.SetCurrentDay28(*i)
}
return dkc
}
// SetID sets the "id" field.
func (dkc *DeviceKpiCreate) SetID(u uint64) *DeviceKpiCreate {
dkc.mutation.SetID(u)
return dkc
}
// Mutation returns the DeviceKpiMutation object of the builder.
func (dkc *DeviceKpiCreate) Mutation() *DeviceKpiMutation {
return dkc.mutation
}
// Save creates the DeviceKpi in the database.
func (dkc *DeviceKpiCreate) Save(ctx context.Context) (*DeviceKpi, error) {
dkc.defaults()
return withHooks(ctx, dkc.sqlSave, dkc.mutation, dkc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dkc *DeviceKpiCreate) SaveX(ctx context.Context) *DeviceKpi {
v, err := dkc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dkc *DeviceKpiCreate) Exec(ctx context.Context) error {
_, err := dkc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dkc *DeviceKpiCreate) ExecX(ctx context.Context) {
if err := dkc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dkc *DeviceKpiCreate) defaults() {
if _, ok := dkc.mutation.CreatedAt(); !ok {
v := devicekpi.DefaultCreatedAt()
dkc.mutation.SetCreatedAt(v)
}
if _, ok := dkc.mutation.UpdatedAt(); !ok {
v := devicekpi.DefaultUpdatedAt()
dkc.mutation.SetUpdatedAt(v)
}
if _, ok := dkc.mutation.Status(); !ok {
v := devicekpi.DefaultStatus
dkc.mutation.SetStatus(v)
}
if _, ok := dkc.mutation.Sort(); !ok {
v := devicekpi.DefaultSort
dkc.mutation.SetSort(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dkc *DeviceKpiCreate) check() error {
if _, ok := dkc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DeviceKpi.created_at"`)}
}
if _, ok := dkc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DeviceKpi.updated_at"`)}
}
if _, ok := dkc.mutation.Sort(); !ok {
return &ValidationError{Name: "sort", err: errors.New(`ent: missing required field "DeviceKpi.sort"`)}
}
if _, ok := dkc.mutation.IotID(); !ok {
return &ValidationError{Name: "iotID", err: errors.New(`ent: missing required field "DeviceKpi.iotID"`)}
}
if _, ok := dkc.mutation.DeviceName(); !ok {
return &ValidationError{Name: "deviceName", err: errors.New(`ent: missing required field "DeviceKpi.deviceName"`)}
}
if _, ok := dkc.mutation.ProductKey(); !ok {
return &ValidationError{Name: "productKey", err: errors.New(`ent: missing required field "DeviceKpi.productKey"`)}
}
return nil
}
func (dkc *DeviceKpiCreate) sqlSave(ctx context.Context) (*DeviceKpi, error) {
if err := dkc.check(); err != nil {
return nil, err
}
_node, _spec := dkc.createSpec()
if err := sqlgraph.CreateNode(ctx, dkc.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 = uint64(id)
}
dkc.mutation.id = &_node.ID
dkc.mutation.done = true
return _node, nil
}
func (dkc *DeviceKpiCreate) createSpec() (*DeviceKpi, *sqlgraph.CreateSpec) {
var (
_node = &DeviceKpi{config: dkc.config}
_spec = sqlgraph.NewCreateSpec(devicekpi.Table, sqlgraph.NewFieldSpec(devicekpi.FieldID, field.TypeUint64))
)
if dkc.Table != "" {
_spec.Table = dkc.Table
}
_spec.OnConflict = dkc.conflict
if id, ok := dkc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := dkc.mutation.CreatedAt(); ok {
_spec.SetField(devicekpi.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dkc.mutation.UpdatedAt(); ok {
_spec.SetField(devicekpi.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := dkc.mutation.Status(); ok {
_spec.SetField(devicekpi.FieldStatus, field.TypeUint8, value)
_node.Status = value
}
if value, ok := dkc.mutation.Sort(); ok {
_spec.SetField(devicekpi.FieldSort, field.TypeUint32, value)
_node.Sort = value
}
if value, ok := dkc.mutation.IotID(); ok {
_spec.SetField(devicekpi.FieldIotID, field.TypeString, value)
_node.IotID = value
}
if value, ok := dkc.mutation.DeviceName(); ok {
_spec.SetField(devicekpi.FieldDeviceName, field.TypeString, value)
_node.DeviceName = value
}
if value, ok := dkc.mutation.ProductKey(); ok {
_spec.SetField(devicekpi.FieldProductKey, field.TypeString, value)
_node.ProductKey = value
}
if value, ok := dkc.mutation.Kpi(); ok {
_spec.SetField(devicekpi.FieldKpi, field.TypeFloat64, value)
_node.Kpi = value
}
if value, ok := dkc.mutation.X(); ok {
_spec.SetField(devicekpi.FieldX, field.TypeFloat64, value)
_node.X = value
}
if value, ok := dkc.mutation.Y(); ok {
_spec.SetField(devicekpi.FieldY, field.TypeFloat64, value)
_node.Y = value
}
if value, ok := dkc.mutation.A(); ok {
_spec.SetField(devicekpi.FieldA, field.TypeFloat64, value)
_node.A = value
}
if value, ok := dkc.mutation.B(); ok {
_spec.SetField(devicekpi.FieldB, field.TypeFloat64, value)
_node.B = value
}
if value, ok := dkc.mutation.WeekKpi(); ok {
_spec.SetField(devicekpi.FieldWeekKpi, field.TypeFloat64, value)
_node.WeekKpi = value
}
if value, ok := dkc.mutation.MonthKpi(); ok {
_spec.SetField(devicekpi.FieldMonthKpi, field.TypeFloat64, value)
_node.MonthKpi = value
}
if value, ok := dkc.mutation.CurrentDay1(); ok {
_spec.SetField(devicekpi.FieldCurrentDay1, field.TypeInt64, value)
_node.CurrentDay1 = value
}
if value, ok := dkc.mutation.CurrentDay7(); ok {
_spec.SetField(devicekpi.FieldCurrentDay7, field.TypeInt64, value)
_node.CurrentDay7 = value
}
if value, ok := dkc.mutation.CurrentDay28(); ok {
_spec.SetField(devicekpi.FieldCurrentDay28, field.TypeInt64, value)
_node.CurrentDay28 = value
}
return _node, _spec
}
func (dkc *DeviceKpiCreate) TableName(s string) *DeviceKpiCreate {
dkc.Table = s
return dkc
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.DeviceKpi.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.DeviceKpiUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dkc *DeviceKpiCreate) OnConflict(opts ...sql.ConflictOption) *DeviceKpiUpsertOne {
dkc.conflict = opts
return &DeviceKpiUpsertOne{
create: dkc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dkc *DeviceKpiCreate) OnConflictColumns(columns ...string) *DeviceKpiUpsertOne {
dkc.conflict = append(dkc.conflict, sql.ConflictColumns(columns...))
return &DeviceKpiUpsertOne{
create: dkc,
}
}
type (
// DeviceKpiUpsertOne is the builder for "upsert"-ing
// one DeviceKpi node.
DeviceKpiUpsertOne struct {
create *DeviceKpiCreate
}
// DeviceKpiUpsert is the "OnConflict" setter.
DeviceKpiUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceKpiUpsert) SetUpdatedAt(v time.Time) *DeviceKpiUpsert {
u.Set(devicekpi.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateUpdatedAt() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldUpdatedAt)
return u
}
// SetStatus sets the "status" field.
func (u *DeviceKpiUpsert) SetStatus(v uint8) *DeviceKpiUpsert {
u.Set(devicekpi.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateStatus() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldStatus)
return u
}
// AddStatus adds v to the "status" field.
func (u *DeviceKpiUpsert) AddStatus(v uint8) *DeviceKpiUpsert {
u.Add(devicekpi.FieldStatus, v)
return u
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceKpiUpsert) ClearStatus() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldStatus)
return u
}
// SetSort sets the "sort" field.
func (u *DeviceKpiUpsert) SetSort(v uint32) *DeviceKpiUpsert {
u.Set(devicekpi.FieldSort, v)
return u
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateSort() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldSort)
return u
}
// AddSort adds v to the "sort" field.
func (u *DeviceKpiUpsert) AddSort(v uint32) *DeviceKpiUpsert {
u.Add(devicekpi.FieldSort, v)
return u
}
// SetIotID sets the "iotID" field.
func (u *DeviceKpiUpsert) SetIotID(v string) *DeviceKpiUpsert {
u.Set(devicekpi.FieldIotID, v)
return u
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateIotID() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldIotID)
return u
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceKpiUpsert) SetDeviceName(v string) *DeviceKpiUpsert {
u.Set(devicekpi.FieldDeviceName, v)
return u
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateDeviceName() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldDeviceName)
return u
}
// SetProductKey sets the "productKey" field.
func (u *DeviceKpiUpsert) SetProductKey(v string) *DeviceKpiUpsert {
u.Set(devicekpi.FieldProductKey, v)
return u
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateProductKey() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldProductKey)
return u
}
// SetKpi sets the "kpi" field.
func (u *DeviceKpiUpsert) SetKpi(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldKpi, v)
return u
}
// UpdateKpi sets the "kpi" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateKpi() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldKpi)
return u
}
// AddKpi adds v to the "kpi" field.
func (u *DeviceKpiUpsert) AddKpi(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldKpi, v)
return u
}
// ClearKpi clears the value of the "kpi" field.
func (u *DeviceKpiUpsert) ClearKpi() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldKpi)
return u
}
// SetX sets the "x" field.
func (u *DeviceKpiUpsert) SetX(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldX, v)
return u
}
// UpdateX sets the "x" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateX() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldX)
return u
}
// AddX adds v to the "x" field.
func (u *DeviceKpiUpsert) AddX(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldX, v)
return u
}
// ClearX clears the value of the "x" field.
func (u *DeviceKpiUpsert) ClearX() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldX)
return u
}
// SetY sets the "y" field.
func (u *DeviceKpiUpsert) SetY(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldY, v)
return u
}
// UpdateY sets the "y" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateY() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldY)
return u
}
// AddY adds v to the "y" field.
func (u *DeviceKpiUpsert) AddY(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldY, v)
return u
}
// ClearY clears the value of the "y" field.
func (u *DeviceKpiUpsert) ClearY() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldY)
return u
}
// SetA sets the "a" field.
func (u *DeviceKpiUpsert) SetA(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldA, v)
return u
}
// UpdateA sets the "a" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateA() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldA)
return u
}
// AddA adds v to the "a" field.
func (u *DeviceKpiUpsert) AddA(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldA, v)
return u
}
// ClearA clears the value of the "a" field.
func (u *DeviceKpiUpsert) ClearA() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldA)
return u
}
// SetB sets the "b" field.
func (u *DeviceKpiUpsert) SetB(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldB, v)
return u
}
// UpdateB sets the "b" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateB() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldB)
return u
}
// AddB adds v to the "b" field.
func (u *DeviceKpiUpsert) AddB(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldB, v)
return u
}
// ClearB clears the value of the "b" field.
func (u *DeviceKpiUpsert) ClearB() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldB)
return u
}
// SetWeekKpi sets the "weekKpi" field.
func (u *DeviceKpiUpsert) SetWeekKpi(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldWeekKpi, v)
return u
}
// UpdateWeekKpi sets the "weekKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateWeekKpi() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldWeekKpi)
return u
}
// AddWeekKpi adds v to the "weekKpi" field.
func (u *DeviceKpiUpsert) AddWeekKpi(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldWeekKpi, v)
return u
}
// ClearWeekKpi clears the value of the "weekKpi" field.
func (u *DeviceKpiUpsert) ClearWeekKpi() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldWeekKpi)
return u
}
// SetMonthKpi sets the "monthKpi" field.
func (u *DeviceKpiUpsert) SetMonthKpi(v float64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldMonthKpi, v)
return u
}
// UpdateMonthKpi sets the "monthKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateMonthKpi() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldMonthKpi)
return u
}
// AddMonthKpi adds v to the "monthKpi" field.
func (u *DeviceKpiUpsert) AddMonthKpi(v float64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldMonthKpi, v)
return u
}
// ClearMonthKpi clears the value of the "monthKpi" field.
func (u *DeviceKpiUpsert) ClearMonthKpi() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldMonthKpi)
return u
}
// SetCurrentDay1 sets the "currentDay1" field.
func (u *DeviceKpiUpsert) SetCurrentDay1(v int64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldCurrentDay1, v)
return u
}
// UpdateCurrentDay1 sets the "currentDay1" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateCurrentDay1() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldCurrentDay1)
return u
}
// AddCurrentDay1 adds v to the "currentDay1" field.
func (u *DeviceKpiUpsert) AddCurrentDay1(v int64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldCurrentDay1, v)
return u
}
// ClearCurrentDay1 clears the value of the "currentDay1" field.
func (u *DeviceKpiUpsert) ClearCurrentDay1() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldCurrentDay1)
return u
}
// SetCurrentDay7 sets the "currentDay7" field.
func (u *DeviceKpiUpsert) SetCurrentDay7(v int64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldCurrentDay7, v)
return u
}
// UpdateCurrentDay7 sets the "currentDay7" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateCurrentDay7() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldCurrentDay7)
return u
}
// AddCurrentDay7 adds v to the "currentDay7" field.
func (u *DeviceKpiUpsert) AddCurrentDay7(v int64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldCurrentDay7, v)
return u
}
// ClearCurrentDay7 clears the value of the "currentDay7" field.
func (u *DeviceKpiUpsert) ClearCurrentDay7() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldCurrentDay7)
return u
}
// SetCurrentDay28 sets the "currentDay28" field.
func (u *DeviceKpiUpsert) SetCurrentDay28(v int64) *DeviceKpiUpsert {
u.Set(devicekpi.FieldCurrentDay28, v)
return u
}
// UpdateCurrentDay28 sets the "currentDay28" field to the value that was provided on create.
func (u *DeviceKpiUpsert) UpdateCurrentDay28() *DeviceKpiUpsert {
u.SetExcluded(devicekpi.FieldCurrentDay28)
return u
}
// AddCurrentDay28 adds v to the "currentDay28" field.
func (u *DeviceKpiUpsert) AddCurrentDay28(v int64) *DeviceKpiUpsert {
u.Add(devicekpi.FieldCurrentDay28, v)
return u
}
// ClearCurrentDay28 clears the value of the "currentDay28" field.
func (u *DeviceKpiUpsert) ClearCurrentDay28() *DeviceKpiUpsert {
u.SetNull(devicekpi.FieldCurrentDay28)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(devicekpi.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceKpiUpsertOne) UpdateNewValues() *DeviceKpiUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(devicekpi.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(devicekpi.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceKpiUpsertOne) Ignore() *DeviceKpiUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DeviceKpiUpsertOne) DoNothing() *DeviceKpiUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceKpiCreate.OnConflict
// documentation for more info.
func (u *DeviceKpiUpsertOne) Update(set func(*DeviceKpiUpsert)) *DeviceKpiUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceKpiUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceKpiUpsertOne) SetUpdatedAt(v time.Time) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateUpdatedAt() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceKpiUpsertOne) SetStatus(v uint8) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceKpiUpsertOne) AddStatus(v uint8) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateStatus() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceKpiUpsertOne) ClearStatus() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceKpiUpsertOne) SetSort(v uint32) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceKpiUpsertOne) AddSort(v uint32) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateSort() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateSort()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceKpiUpsertOne) SetIotID(v string) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateIotID() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceKpiUpsertOne) SetDeviceName(v string) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateDeviceName() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateDeviceName()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceKpiUpsertOne) SetProductKey(v string) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateProductKey() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateProductKey()
})
}
// SetKpi sets the "kpi" field.
func (u *DeviceKpiUpsertOne) SetKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetKpi(v)
})
}
// AddKpi adds v to the "kpi" field.
func (u *DeviceKpiUpsertOne) AddKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddKpi(v)
})
}
// UpdateKpi sets the "kpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateKpi()
})
}
// ClearKpi clears the value of the "kpi" field.
func (u *DeviceKpiUpsertOne) ClearKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearKpi()
})
}
// SetX sets the "x" field.
func (u *DeviceKpiUpsertOne) SetX(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetX(v)
})
}
// AddX adds v to the "x" field.
func (u *DeviceKpiUpsertOne) AddX(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddX(v)
})
}
// UpdateX sets the "x" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateX() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateX()
})
}
// ClearX clears the value of the "x" field.
func (u *DeviceKpiUpsertOne) ClearX() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearX()
})
}
// SetY sets the "y" field.
func (u *DeviceKpiUpsertOne) SetY(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetY(v)
})
}
// AddY adds v to the "y" field.
func (u *DeviceKpiUpsertOne) AddY(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddY(v)
})
}
// UpdateY sets the "y" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateY() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateY()
})
}
// ClearY clears the value of the "y" field.
func (u *DeviceKpiUpsertOne) ClearY() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearY()
})
}
// SetA sets the "a" field.
func (u *DeviceKpiUpsertOne) SetA(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetA(v)
})
}
// AddA adds v to the "a" field.
func (u *DeviceKpiUpsertOne) AddA(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddA(v)
})
}
// UpdateA sets the "a" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateA() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateA()
})
}
// ClearA clears the value of the "a" field.
func (u *DeviceKpiUpsertOne) ClearA() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearA()
})
}
// SetB sets the "b" field.
func (u *DeviceKpiUpsertOne) SetB(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetB(v)
})
}
// AddB adds v to the "b" field.
func (u *DeviceKpiUpsertOne) AddB(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddB(v)
})
}
// UpdateB sets the "b" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateB() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateB()
})
}
// ClearB clears the value of the "b" field.
func (u *DeviceKpiUpsertOne) ClearB() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearB()
})
}
// SetWeekKpi sets the "weekKpi" field.
func (u *DeviceKpiUpsertOne) SetWeekKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetWeekKpi(v)
})
}
// AddWeekKpi adds v to the "weekKpi" field.
func (u *DeviceKpiUpsertOne) AddWeekKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddWeekKpi(v)
})
}
// UpdateWeekKpi sets the "weekKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateWeekKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateWeekKpi()
})
}
// ClearWeekKpi clears the value of the "weekKpi" field.
func (u *DeviceKpiUpsertOne) ClearWeekKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearWeekKpi()
})
}
// SetMonthKpi sets the "monthKpi" field.
func (u *DeviceKpiUpsertOne) SetMonthKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetMonthKpi(v)
})
}
// AddMonthKpi adds v to the "monthKpi" field.
func (u *DeviceKpiUpsertOne) AddMonthKpi(v float64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddMonthKpi(v)
})
}
// UpdateMonthKpi sets the "monthKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateMonthKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateMonthKpi()
})
}
// ClearMonthKpi clears the value of the "monthKpi" field.
func (u *DeviceKpiUpsertOne) ClearMonthKpi() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearMonthKpi()
})
}
// SetCurrentDay1 sets the "currentDay1" field.
func (u *DeviceKpiUpsertOne) SetCurrentDay1(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay1(v)
})
}
// AddCurrentDay1 adds v to the "currentDay1" field.
func (u *DeviceKpiUpsertOne) AddCurrentDay1(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay1(v)
})
}
// UpdateCurrentDay1 sets the "currentDay1" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateCurrentDay1() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay1()
})
}
// ClearCurrentDay1 clears the value of the "currentDay1" field.
func (u *DeviceKpiUpsertOne) ClearCurrentDay1() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay1()
})
}
// SetCurrentDay7 sets the "currentDay7" field.
func (u *DeviceKpiUpsertOne) SetCurrentDay7(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay7(v)
})
}
// AddCurrentDay7 adds v to the "currentDay7" field.
func (u *DeviceKpiUpsertOne) AddCurrentDay7(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay7(v)
})
}
// UpdateCurrentDay7 sets the "currentDay7" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateCurrentDay7() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay7()
})
}
// ClearCurrentDay7 clears the value of the "currentDay7" field.
func (u *DeviceKpiUpsertOne) ClearCurrentDay7() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay7()
})
}
// SetCurrentDay28 sets the "currentDay28" field.
func (u *DeviceKpiUpsertOne) SetCurrentDay28(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay28(v)
})
}
// AddCurrentDay28 adds v to the "currentDay28" field.
func (u *DeviceKpiUpsertOne) AddCurrentDay28(v int64) *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay28(v)
})
}
// UpdateCurrentDay28 sets the "currentDay28" field to the value that was provided on create.
func (u *DeviceKpiUpsertOne) UpdateCurrentDay28() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay28()
})
}
// ClearCurrentDay28 clears the value of the "currentDay28" field.
func (u *DeviceKpiUpsertOne) ClearCurrentDay28() *DeviceKpiUpsertOne {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay28()
})
}
// Exec executes the query.
func (u *DeviceKpiUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceKpiCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceKpiUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *DeviceKpiUpsertOne) ID(ctx context.Context) (id uint64, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *DeviceKpiUpsertOne) IDX(ctx context.Context) uint64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// DeviceKpiCreateBulk is the builder for creating many DeviceKpi entities in bulk.
type DeviceKpiCreateBulk struct {
config
err error
builders []*DeviceKpiCreate
conflict []sql.ConflictOption
}
// Save creates the DeviceKpi entities in the database.
func (dkcb *DeviceKpiCreateBulk) Save(ctx context.Context) ([]*DeviceKpi, error) {
if dkcb.err != nil {
return nil, dkcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dkcb.builders))
nodes := make([]*DeviceKpi, len(dkcb.builders))
mutators := make([]Mutator, len(dkcb.builders))
for i := range dkcb.builders {
func(i int, root context.Context) {
builder := dkcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DeviceKpiMutation)
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, dkcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = dkcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dkcb.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 = uint64(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, dkcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dkcb *DeviceKpiCreateBulk) SaveX(ctx context.Context) []*DeviceKpi {
v, err := dkcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dkcb *DeviceKpiCreateBulk) Exec(ctx context.Context) error {
_, err := dkcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dkcb *DeviceKpiCreateBulk) ExecX(ctx context.Context) {
if err := dkcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.DeviceKpi.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.DeviceKpiUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dkcb *DeviceKpiCreateBulk) OnConflict(opts ...sql.ConflictOption) *DeviceKpiUpsertBulk {
dkcb.conflict = opts
return &DeviceKpiUpsertBulk{
create: dkcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dkcb *DeviceKpiCreateBulk) OnConflictColumns(columns ...string) *DeviceKpiUpsertBulk {
dkcb.conflict = append(dkcb.conflict, sql.ConflictColumns(columns...))
return &DeviceKpiUpsertBulk{
create: dkcb,
}
}
// DeviceKpiUpsertBulk is the builder for "upsert"-ing
// a bulk of DeviceKpi nodes.
type DeviceKpiUpsertBulk struct {
create *DeviceKpiCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(devicekpi.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceKpiUpsertBulk) UpdateNewValues() *DeviceKpiUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(devicekpi.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(devicekpi.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeviceKpi.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceKpiUpsertBulk) Ignore() *DeviceKpiUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DeviceKpiUpsertBulk) DoNothing() *DeviceKpiUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceKpiCreateBulk.OnConflict
// documentation for more info.
func (u *DeviceKpiUpsertBulk) Update(set func(*DeviceKpiUpsert)) *DeviceKpiUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceKpiUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceKpiUpsertBulk) SetUpdatedAt(v time.Time) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateUpdatedAt() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceKpiUpsertBulk) SetStatus(v uint8) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceKpiUpsertBulk) AddStatus(v uint8) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateStatus() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceKpiUpsertBulk) ClearStatus() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceKpiUpsertBulk) SetSort(v uint32) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceKpiUpsertBulk) AddSort(v uint32) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateSort() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateSort()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceKpiUpsertBulk) SetIotID(v string) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateIotID() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceKpiUpsertBulk) SetDeviceName(v string) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateDeviceName() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateDeviceName()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceKpiUpsertBulk) SetProductKey(v string) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateProductKey() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateProductKey()
})
}
// SetKpi sets the "kpi" field.
func (u *DeviceKpiUpsertBulk) SetKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetKpi(v)
})
}
// AddKpi adds v to the "kpi" field.
func (u *DeviceKpiUpsertBulk) AddKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddKpi(v)
})
}
// UpdateKpi sets the "kpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateKpi()
})
}
// ClearKpi clears the value of the "kpi" field.
func (u *DeviceKpiUpsertBulk) ClearKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearKpi()
})
}
// SetX sets the "x" field.
func (u *DeviceKpiUpsertBulk) SetX(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetX(v)
})
}
// AddX adds v to the "x" field.
func (u *DeviceKpiUpsertBulk) AddX(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddX(v)
})
}
// UpdateX sets the "x" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateX() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateX()
})
}
// ClearX clears the value of the "x" field.
func (u *DeviceKpiUpsertBulk) ClearX() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearX()
})
}
// SetY sets the "y" field.
func (u *DeviceKpiUpsertBulk) SetY(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetY(v)
})
}
// AddY adds v to the "y" field.
func (u *DeviceKpiUpsertBulk) AddY(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddY(v)
})
}
// UpdateY sets the "y" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateY() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateY()
})
}
// ClearY clears the value of the "y" field.
func (u *DeviceKpiUpsertBulk) ClearY() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearY()
})
}
// SetA sets the "a" field.
func (u *DeviceKpiUpsertBulk) SetA(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetA(v)
})
}
// AddA adds v to the "a" field.
func (u *DeviceKpiUpsertBulk) AddA(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddA(v)
})
}
// UpdateA sets the "a" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateA() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateA()
})
}
// ClearA clears the value of the "a" field.
func (u *DeviceKpiUpsertBulk) ClearA() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearA()
})
}
// SetB sets the "b" field.
func (u *DeviceKpiUpsertBulk) SetB(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetB(v)
})
}
// AddB adds v to the "b" field.
func (u *DeviceKpiUpsertBulk) AddB(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddB(v)
})
}
// UpdateB sets the "b" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateB() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateB()
})
}
// ClearB clears the value of the "b" field.
func (u *DeviceKpiUpsertBulk) ClearB() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearB()
})
}
// SetWeekKpi sets the "weekKpi" field.
func (u *DeviceKpiUpsertBulk) SetWeekKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetWeekKpi(v)
})
}
// AddWeekKpi adds v to the "weekKpi" field.
func (u *DeviceKpiUpsertBulk) AddWeekKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddWeekKpi(v)
})
}
// UpdateWeekKpi sets the "weekKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateWeekKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateWeekKpi()
})
}
// ClearWeekKpi clears the value of the "weekKpi" field.
func (u *DeviceKpiUpsertBulk) ClearWeekKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearWeekKpi()
})
}
// SetMonthKpi sets the "monthKpi" field.
func (u *DeviceKpiUpsertBulk) SetMonthKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetMonthKpi(v)
})
}
// AddMonthKpi adds v to the "monthKpi" field.
func (u *DeviceKpiUpsertBulk) AddMonthKpi(v float64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddMonthKpi(v)
})
}
// UpdateMonthKpi sets the "monthKpi" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateMonthKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateMonthKpi()
})
}
// ClearMonthKpi clears the value of the "monthKpi" field.
func (u *DeviceKpiUpsertBulk) ClearMonthKpi() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearMonthKpi()
})
}
// SetCurrentDay1 sets the "currentDay1" field.
func (u *DeviceKpiUpsertBulk) SetCurrentDay1(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay1(v)
})
}
// AddCurrentDay1 adds v to the "currentDay1" field.
func (u *DeviceKpiUpsertBulk) AddCurrentDay1(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay1(v)
})
}
// UpdateCurrentDay1 sets the "currentDay1" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateCurrentDay1() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay1()
})
}
// ClearCurrentDay1 clears the value of the "currentDay1" field.
func (u *DeviceKpiUpsertBulk) ClearCurrentDay1() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay1()
})
}
// SetCurrentDay7 sets the "currentDay7" field.
func (u *DeviceKpiUpsertBulk) SetCurrentDay7(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay7(v)
})
}
// AddCurrentDay7 adds v to the "currentDay7" field.
func (u *DeviceKpiUpsertBulk) AddCurrentDay7(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay7(v)
})
}
// UpdateCurrentDay7 sets the "currentDay7" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateCurrentDay7() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay7()
})
}
// ClearCurrentDay7 clears the value of the "currentDay7" field.
func (u *DeviceKpiUpsertBulk) ClearCurrentDay7() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay7()
})
}
// SetCurrentDay28 sets the "currentDay28" field.
func (u *DeviceKpiUpsertBulk) SetCurrentDay28(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.SetCurrentDay28(v)
})
}
// AddCurrentDay28 adds v to the "currentDay28" field.
func (u *DeviceKpiUpsertBulk) AddCurrentDay28(v int64) *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.AddCurrentDay28(v)
})
}
// UpdateCurrentDay28 sets the "currentDay28" field to the value that was provided on create.
func (u *DeviceKpiUpsertBulk) UpdateCurrentDay28() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.UpdateCurrentDay28()
})
}
// ClearCurrentDay28 clears the value of the "currentDay28" field.
func (u *DeviceKpiUpsertBulk) ClearCurrentDay28() *DeviceKpiUpsertBulk {
return u.Update(func(s *DeviceKpiUpsert) {
s.ClearCurrentDay28()
})
}
// Exec executes the query.
func (u *DeviceKpiUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the DeviceKpiCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceKpiCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceKpiUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。