代码拉取完成,页面将自动刷新
// 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/deviceofflinetime"
)
// DeviceOfflineTimeCreate is the builder for creating a DeviceOfflineTime entity.
type DeviceOfflineTimeCreate struct {
config
mutation *DeviceOfflineTimeMutation
hooks []Hook
Table string
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (dotc *DeviceOfflineTimeCreate) SetCreatedAt(t time.Time) *DeviceOfflineTimeCreate {
dotc.mutation.SetCreatedAt(t)
return dotc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dotc *DeviceOfflineTimeCreate) SetNillableCreatedAt(t *time.Time) *DeviceOfflineTimeCreate {
if t != nil {
dotc.SetCreatedAt(*t)
}
return dotc
}
// SetUpdatedAt sets the "updated_at" field.
func (dotc *DeviceOfflineTimeCreate) SetUpdatedAt(t time.Time) *DeviceOfflineTimeCreate {
dotc.mutation.SetUpdatedAt(t)
return dotc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dotc *DeviceOfflineTimeCreate) SetNillableUpdatedAt(t *time.Time) *DeviceOfflineTimeCreate {
if t != nil {
dotc.SetUpdatedAt(*t)
}
return dotc
}
// SetStatus sets the "status" field.
func (dotc *DeviceOfflineTimeCreate) SetStatus(u uint8) *DeviceOfflineTimeCreate {
dotc.mutation.SetStatus(u)
return dotc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dotc *DeviceOfflineTimeCreate) SetNillableStatus(u *uint8) *DeviceOfflineTimeCreate {
if u != nil {
dotc.SetStatus(*u)
}
return dotc
}
// SetSort sets the "sort" field.
func (dotc *DeviceOfflineTimeCreate) SetSort(u uint32) *DeviceOfflineTimeCreate {
dotc.mutation.SetSort(u)
return dotc
}
// SetNillableSort sets the "sort" field if the given value is not nil.
func (dotc *DeviceOfflineTimeCreate) SetNillableSort(u *uint32) *DeviceOfflineTimeCreate {
if u != nil {
dotc.SetSort(*u)
}
return dotc
}
// SetIotID sets the "iotID" field.
func (dotc *DeviceOfflineTimeCreate) SetIotID(s string) *DeviceOfflineTimeCreate {
dotc.mutation.SetIotID(s)
return dotc
}
// SetDeviceName sets the "deviceName" field.
func (dotc *DeviceOfflineTimeCreate) SetDeviceName(s string) *DeviceOfflineTimeCreate {
dotc.mutation.SetDeviceName(s)
return dotc
}
// SetProductKey sets the "productKey" field.
func (dotc *DeviceOfflineTimeCreate) SetProductKey(s string) *DeviceOfflineTimeCreate {
dotc.mutation.SetProductKey(s)
return dotc
}
// SetTime sets the "time" field.
func (dotc *DeviceOfflineTimeCreate) SetTime(s string) *DeviceOfflineTimeCreate {
dotc.mutation.SetTime(s)
return dotc
}
// SetNillableTime sets the "time" field if the given value is not nil.
func (dotc *DeviceOfflineTimeCreate) SetNillableTime(s *string) *DeviceOfflineTimeCreate {
if s != nil {
dotc.SetTime(*s)
}
return dotc
}
// SetID sets the "id" field.
func (dotc *DeviceOfflineTimeCreate) SetID(u uint64) *DeviceOfflineTimeCreate {
dotc.mutation.SetID(u)
return dotc
}
// Mutation returns the DeviceOfflineTimeMutation object of the builder.
func (dotc *DeviceOfflineTimeCreate) Mutation() *DeviceOfflineTimeMutation {
return dotc.mutation
}
// Save creates the DeviceOfflineTime in the database.
func (dotc *DeviceOfflineTimeCreate) Save(ctx context.Context) (*DeviceOfflineTime, error) {
dotc.defaults()
return withHooks(ctx, dotc.sqlSave, dotc.mutation, dotc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dotc *DeviceOfflineTimeCreate) SaveX(ctx context.Context) *DeviceOfflineTime {
v, err := dotc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dotc *DeviceOfflineTimeCreate) Exec(ctx context.Context) error {
_, err := dotc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dotc *DeviceOfflineTimeCreate) ExecX(ctx context.Context) {
if err := dotc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dotc *DeviceOfflineTimeCreate) defaults() {
if _, ok := dotc.mutation.CreatedAt(); !ok {
v := deviceofflinetime.DefaultCreatedAt()
dotc.mutation.SetCreatedAt(v)
}
if _, ok := dotc.mutation.UpdatedAt(); !ok {
v := deviceofflinetime.DefaultUpdatedAt()
dotc.mutation.SetUpdatedAt(v)
}
if _, ok := dotc.mutation.Status(); !ok {
v := deviceofflinetime.DefaultStatus
dotc.mutation.SetStatus(v)
}
if _, ok := dotc.mutation.Sort(); !ok {
v := deviceofflinetime.DefaultSort
dotc.mutation.SetSort(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dotc *DeviceOfflineTimeCreate) check() error {
if _, ok := dotc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DeviceOfflineTime.created_at"`)}
}
if _, ok := dotc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DeviceOfflineTime.updated_at"`)}
}
if _, ok := dotc.mutation.Sort(); !ok {
return &ValidationError{Name: "sort", err: errors.New(`ent: missing required field "DeviceOfflineTime.sort"`)}
}
if _, ok := dotc.mutation.IotID(); !ok {
return &ValidationError{Name: "iotID", err: errors.New(`ent: missing required field "DeviceOfflineTime.iotID"`)}
}
if _, ok := dotc.mutation.DeviceName(); !ok {
return &ValidationError{Name: "deviceName", err: errors.New(`ent: missing required field "DeviceOfflineTime.deviceName"`)}
}
if _, ok := dotc.mutation.ProductKey(); !ok {
return &ValidationError{Name: "productKey", err: errors.New(`ent: missing required field "DeviceOfflineTime.productKey"`)}
}
return nil
}
func (dotc *DeviceOfflineTimeCreate) sqlSave(ctx context.Context) (*DeviceOfflineTime, error) {
if err := dotc.check(); err != nil {
return nil, err
}
_node, _spec := dotc.createSpec()
if err := sqlgraph.CreateNode(ctx, dotc.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)
}
dotc.mutation.id = &_node.ID
dotc.mutation.done = true
return _node, nil
}
func (dotc *DeviceOfflineTimeCreate) createSpec() (*DeviceOfflineTime, *sqlgraph.CreateSpec) {
var (
_node = &DeviceOfflineTime{config: dotc.config}
_spec = sqlgraph.NewCreateSpec(deviceofflinetime.Table, sqlgraph.NewFieldSpec(deviceofflinetime.FieldID, field.TypeUint64))
)
if dotc.Table != "" {
_spec.Table = dotc.Table
}
_spec.OnConflict = dotc.conflict
if id, ok := dotc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := dotc.mutation.CreatedAt(); ok {
_spec.SetField(deviceofflinetime.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dotc.mutation.UpdatedAt(); ok {
_spec.SetField(deviceofflinetime.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := dotc.mutation.Status(); ok {
_spec.SetField(deviceofflinetime.FieldStatus, field.TypeUint8, value)
_node.Status = value
}
if value, ok := dotc.mutation.Sort(); ok {
_spec.SetField(deviceofflinetime.FieldSort, field.TypeUint32, value)
_node.Sort = value
}
if value, ok := dotc.mutation.IotID(); ok {
_spec.SetField(deviceofflinetime.FieldIotID, field.TypeString, value)
_node.IotID = value
}
if value, ok := dotc.mutation.DeviceName(); ok {
_spec.SetField(deviceofflinetime.FieldDeviceName, field.TypeString, value)
_node.DeviceName = value
}
if value, ok := dotc.mutation.ProductKey(); ok {
_spec.SetField(deviceofflinetime.FieldProductKey, field.TypeString, value)
_node.ProductKey = value
}
if value, ok := dotc.mutation.Time(); ok {
_spec.SetField(deviceofflinetime.FieldTime, field.TypeString, value)
_node.Time = value
}
return _node, _spec
}
func (dotc *DeviceOfflineTimeCreate) TableName(s string) *DeviceOfflineTimeCreate {
dotc.Table = s
return dotc
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.DeviceOfflineTime.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.DeviceOfflineTimeUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dotc *DeviceOfflineTimeCreate) OnConflict(opts ...sql.ConflictOption) *DeviceOfflineTimeUpsertOne {
dotc.conflict = opts
return &DeviceOfflineTimeUpsertOne{
create: dotc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeviceOfflineTime.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dotc *DeviceOfflineTimeCreate) OnConflictColumns(columns ...string) *DeviceOfflineTimeUpsertOne {
dotc.conflict = append(dotc.conflict, sql.ConflictColumns(columns...))
return &DeviceOfflineTimeUpsertOne{
create: dotc,
}
}
type (
// DeviceOfflineTimeUpsertOne is the builder for "upsert"-ing
// one DeviceOfflineTime node.
DeviceOfflineTimeUpsertOne struct {
create *DeviceOfflineTimeCreate
}
// DeviceOfflineTimeUpsert is the "OnConflict" setter.
DeviceOfflineTimeUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceOfflineTimeUpsert) SetUpdatedAt(v time.Time) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateUpdatedAt() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldUpdatedAt)
return u
}
// SetStatus sets the "status" field.
func (u *DeviceOfflineTimeUpsert) SetStatus(v uint8) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateStatus() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldStatus)
return u
}
// AddStatus adds v to the "status" field.
func (u *DeviceOfflineTimeUpsert) AddStatus(v uint8) *DeviceOfflineTimeUpsert {
u.Add(deviceofflinetime.FieldStatus, v)
return u
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceOfflineTimeUpsert) ClearStatus() *DeviceOfflineTimeUpsert {
u.SetNull(deviceofflinetime.FieldStatus)
return u
}
// SetSort sets the "sort" field.
func (u *DeviceOfflineTimeUpsert) SetSort(v uint32) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldSort, v)
return u
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateSort() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldSort)
return u
}
// AddSort adds v to the "sort" field.
func (u *DeviceOfflineTimeUpsert) AddSort(v uint32) *DeviceOfflineTimeUpsert {
u.Add(deviceofflinetime.FieldSort, v)
return u
}
// SetIotID sets the "iotID" field.
func (u *DeviceOfflineTimeUpsert) SetIotID(v string) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldIotID, v)
return u
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateIotID() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldIotID)
return u
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceOfflineTimeUpsert) SetDeviceName(v string) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldDeviceName, v)
return u
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateDeviceName() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldDeviceName)
return u
}
// SetProductKey sets the "productKey" field.
func (u *DeviceOfflineTimeUpsert) SetProductKey(v string) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldProductKey, v)
return u
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateProductKey() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldProductKey)
return u
}
// SetTime sets the "time" field.
func (u *DeviceOfflineTimeUpsert) SetTime(v string) *DeviceOfflineTimeUpsert {
u.Set(deviceofflinetime.FieldTime, v)
return u
}
// UpdateTime sets the "time" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsert) UpdateTime() *DeviceOfflineTimeUpsert {
u.SetExcluded(deviceofflinetime.FieldTime)
return u
}
// ClearTime clears the value of the "time" field.
func (u *DeviceOfflineTimeUpsert) ClearTime() *DeviceOfflineTimeUpsert {
u.SetNull(deviceofflinetime.FieldTime)
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.DeviceOfflineTime.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(deviceofflinetime.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceOfflineTimeUpsertOne) UpdateNewValues() *DeviceOfflineTimeUpsertOne {
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(deviceofflinetime.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(deviceofflinetime.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeviceOfflineTime.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceOfflineTimeUpsertOne) Ignore() *DeviceOfflineTimeUpsertOne {
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 *DeviceOfflineTimeUpsertOne) DoNothing() *DeviceOfflineTimeUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceOfflineTimeCreate.OnConflict
// documentation for more info.
func (u *DeviceOfflineTimeUpsertOne) Update(set func(*DeviceOfflineTimeUpsert)) *DeviceOfflineTimeUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceOfflineTimeUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceOfflineTimeUpsertOne) SetUpdatedAt(v time.Time) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateUpdatedAt() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceOfflineTimeUpsertOne) SetStatus(v uint8) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceOfflineTimeUpsertOne) AddStatus(v uint8) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateStatus() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceOfflineTimeUpsertOne) ClearStatus() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceOfflineTimeUpsertOne) SetSort(v uint32) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceOfflineTimeUpsertOne) AddSort(v uint32) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateSort() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateSort()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceOfflineTimeUpsertOne) SetIotID(v string) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateIotID() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceOfflineTimeUpsertOne) SetDeviceName(v string) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateDeviceName() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateDeviceName()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceOfflineTimeUpsertOne) SetProductKey(v string) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateProductKey() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateProductKey()
})
}
// SetTime sets the "time" field.
func (u *DeviceOfflineTimeUpsertOne) SetTime(v string) *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetTime(v)
})
}
// UpdateTime sets the "time" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertOne) UpdateTime() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateTime()
})
}
// ClearTime clears the value of the "time" field.
func (u *DeviceOfflineTimeUpsertOne) ClearTime() *DeviceOfflineTimeUpsertOne {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.ClearTime()
})
}
// Exec executes the query.
func (u *DeviceOfflineTimeUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceOfflineTimeCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceOfflineTimeUpsertOne) 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 *DeviceOfflineTimeUpsertOne) 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 *DeviceOfflineTimeUpsertOne) IDX(ctx context.Context) uint64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// DeviceOfflineTimeCreateBulk is the builder for creating many DeviceOfflineTime entities in bulk.
type DeviceOfflineTimeCreateBulk struct {
config
err error
builders []*DeviceOfflineTimeCreate
conflict []sql.ConflictOption
}
// Save creates the DeviceOfflineTime entities in the database.
func (dotcb *DeviceOfflineTimeCreateBulk) Save(ctx context.Context) ([]*DeviceOfflineTime, error) {
if dotcb.err != nil {
return nil, dotcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dotcb.builders))
nodes := make([]*DeviceOfflineTime, len(dotcb.builders))
mutators := make([]Mutator, len(dotcb.builders))
for i := range dotcb.builders {
func(i int, root context.Context) {
builder := dotcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DeviceOfflineTimeMutation)
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, dotcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = dotcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dotcb.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, dotcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dotcb *DeviceOfflineTimeCreateBulk) SaveX(ctx context.Context) []*DeviceOfflineTime {
v, err := dotcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dotcb *DeviceOfflineTimeCreateBulk) Exec(ctx context.Context) error {
_, err := dotcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dotcb *DeviceOfflineTimeCreateBulk) ExecX(ctx context.Context) {
if err := dotcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.DeviceOfflineTime.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.DeviceOfflineTimeUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dotcb *DeviceOfflineTimeCreateBulk) OnConflict(opts ...sql.ConflictOption) *DeviceOfflineTimeUpsertBulk {
dotcb.conflict = opts
return &DeviceOfflineTimeUpsertBulk{
create: dotcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeviceOfflineTime.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dotcb *DeviceOfflineTimeCreateBulk) OnConflictColumns(columns ...string) *DeviceOfflineTimeUpsertBulk {
dotcb.conflict = append(dotcb.conflict, sql.ConflictColumns(columns...))
return &DeviceOfflineTimeUpsertBulk{
create: dotcb,
}
}
// DeviceOfflineTimeUpsertBulk is the builder for "upsert"-ing
// a bulk of DeviceOfflineTime nodes.
type DeviceOfflineTimeUpsertBulk struct {
create *DeviceOfflineTimeCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.DeviceOfflineTime.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(deviceofflinetime.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceOfflineTimeUpsertBulk) UpdateNewValues() *DeviceOfflineTimeUpsertBulk {
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(deviceofflinetime.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(deviceofflinetime.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeviceOfflineTime.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceOfflineTimeUpsertBulk) Ignore() *DeviceOfflineTimeUpsertBulk {
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 *DeviceOfflineTimeUpsertBulk) DoNothing() *DeviceOfflineTimeUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceOfflineTimeCreateBulk.OnConflict
// documentation for more info.
func (u *DeviceOfflineTimeUpsertBulk) Update(set func(*DeviceOfflineTimeUpsert)) *DeviceOfflineTimeUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceOfflineTimeUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceOfflineTimeUpsertBulk) SetUpdatedAt(v time.Time) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateUpdatedAt() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceOfflineTimeUpsertBulk) SetStatus(v uint8) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceOfflineTimeUpsertBulk) AddStatus(v uint8) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateStatus() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceOfflineTimeUpsertBulk) ClearStatus() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceOfflineTimeUpsertBulk) SetSort(v uint32) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceOfflineTimeUpsertBulk) AddSort(v uint32) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateSort() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateSort()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceOfflineTimeUpsertBulk) SetIotID(v string) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateIotID() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceOfflineTimeUpsertBulk) SetDeviceName(v string) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateDeviceName() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateDeviceName()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceOfflineTimeUpsertBulk) SetProductKey(v string) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateProductKey() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateProductKey()
})
}
// SetTime sets the "time" field.
func (u *DeviceOfflineTimeUpsertBulk) SetTime(v string) *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.SetTime(v)
})
}
// UpdateTime sets the "time" field to the value that was provided on create.
func (u *DeviceOfflineTimeUpsertBulk) UpdateTime() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.UpdateTime()
})
}
// ClearTime clears the value of the "time" field.
func (u *DeviceOfflineTimeUpsertBulk) ClearTime() *DeviceOfflineTimeUpsertBulk {
return u.Update(func(s *DeviceOfflineTimeUpsert) {
s.ClearTime()
})
}
// Exec executes the query.
func (u *DeviceOfflineTimeUpsertBulk) 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 DeviceOfflineTimeCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceOfflineTimeCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceOfflineTimeUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。