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