// 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" "tangled.sh/seiso.moe/aletheia.directory/ent/syncstatus" ) // SyncStatusCreate is the builder for creating a SyncStatus entity. type SyncStatusCreate struct { config mutation *SyncStatusMutation hooks []Hook conflict []sql.ConflictOption } // SetKey sets the "key" field. func (ssc *SyncStatusCreate) SetKey(s string) *SyncStatusCreate { ssc.mutation.SetKey(s) return ssc } // SetLastOperationTime sets the "last_operation_time" field. func (ssc *SyncStatusCreate) SetLastOperationTime(t time.Time) *SyncStatusCreate { ssc.mutation.SetLastOperationTime(t) return ssc } // SetLastSyncTime sets the "last_sync_time" field. func (ssc *SyncStatusCreate) SetLastSyncTime(t time.Time) *SyncStatusCreate { ssc.mutation.SetLastSyncTime(t) return ssc } // Mutation returns the SyncStatusMutation object of the builder. func (ssc *SyncStatusCreate) Mutation() *SyncStatusMutation { return ssc.mutation } // Save creates the SyncStatus in the database. func (ssc *SyncStatusCreate) Save(ctx context.Context) (*SyncStatus, error) { return withHooks(ctx, ssc.sqlSave, ssc.mutation, ssc.hooks) } // SaveX calls Save and panics if Save returns an error. func (ssc *SyncStatusCreate) SaveX(ctx context.Context) *SyncStatus { v, err := ssc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (ssc *SyncStatusCreate) Exec(ctx context.Context) error { _, err := ssc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (ssc *SyncStatusCreate) ExecX(ctx context.Context) { if err := ssc.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (ssc *SyncStatusCreate) check() error { if _, ok := ssc.mutation.Key(); !ok { return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "SyncStatus.key"`)} } if _, ok := ssc.mutation.LastOperationTime(); !ok { return &ValidationError{Name: "last_operation_time", err: errors.New(`ent: missing required field "SyncStatus.last_operation_time"`)} } if _, ok := ssc.mutation.LastSyncTime(); !ok { return &ValidationError{Name: "last_sync_time", err: errors.New(`ent: missing required field "SyncStatus.last_sync_time"`)} } return nil } func (ssc *SyncStatusCreate) sqlSave(ctx context.Context) (*SyncStatus, error) { if err := ssc.check(); err != nil { return nil, err } _node, _spec := ssc.createSpec() if err := sqlgraph.CreateNode(ctx, ssc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } id := _spec.ID.Value.(int64) _node.ID = int(id) ssc.mutation.id = &_node.ID ssc.mutation.done = true return _node, nil } func (ssc *SyncStatusCreate) createSpec() (*SyncStatus, *sqlgraph.CreateSpec) { var ( _node = &SyncStatus{config: ssc.config} _spec = sqlgraph.NewCreateSpec(syncstatus.Table, sqlgraph.NewFieldSpec(syncstatus.FieldID, field.TypeInt)) ) _spec.OnConflict = ssc.conflict if value, ok := ssc.mutation.Key(); ok { _spec.SetField(syncstatus.FieldKey, field.TypeString, value) _node.Key = value } if value, ok := ssc.mutation.LastOperationTime(); ok { _spec.SetField(syncstatus.FieldLastOperationTime, field.TypeTime, value) _node.LastOperationTime = value } if value, ok := ssc.mutation.LastSyncTime(); ok { _spec.SetField(syncstatus.FieldLastSyncTime, field.TypeTime, value) _node.LastSyncTime = value } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.SyncStatus.Create(). // SetKey(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.SyncStatusUpsert) { // SetKey(v+v). // }). // Exec(ctx) func (ssc *SyncStatusCreate) OnConflict(opts ...sql.ConflictOption) *SyncStatusUpsertOne { ssc.conflict = opts return &SyncStatusUpsertOne{ create: ssc, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (ssc *SyncStatusCreate) OnConflictColumns(columns ...string) *SyncStatusUpsertOne { ssc.conflict = append(ssc.conflict, sql.ConflictColumns(columns...)) return &SyncStatusUpsertOne{ create: ssc, } } type ( // SyncStatusUpsertOne is the builder for "upsert"-ing // one SyncStatus node. SyncStatusUpsertOne struct { create *SyncStatusCreate } // SyncStatusUpsert is the "OnConflict" setter. SyncStatusUpsert struct { *sql.UpdateSet } ) // SetKey sets the "key" field. func (u *SyncStatusUpsert) SetKey(v string) *SyncStatusUpsert { u.Set(syncstatus.FieldKey, v) return u } // UpdateKey sets the "key" field to the value that was provided on create. func (u *SyncStatusUpsert) UpdateKey() *SyncStatusUpsert { u.SetExcluded(syncstatus.FieldKey) return u } // SetLastOperationTime sets the "last_operation_time" field. func (u *SyncStatusUpsert) SetLastOperationTime(v time.Time) *SyncStatusUpsert { u.Set(syncstatus.FieldLastOperationTime, v) return u } // UpdateLastOperationTime sets the "last_operation_time" field to the value that was provided on create. func (u *SyncStatusUpsert) UpdateLastOperationTime() *SyncStatusUpsert { u.SetExcluded(syncstatus.FieldLastOperationTime) return u } // SetLastSyncTime sets the "last_sync_time" field. func (u *SyncStatusUpsert) SetLastSyncTime(v time.Time) *SyncStatusUpsert { u.Set(syncstatus.FieldLastSyncTime, v) return u } // UpdateLastSyncTime sets the "last_sync_time" field to the value that was provided on create. func (u *SyncStatusUpsert) UpdateLastSyncTime() *SyncStatusUpsert { u.SetExcluded(syncstatus.FieldLastSyncTime) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SyncStatusUpsertOne) UpdateNewValues() *SyncStatusUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SyncStatusUpsertOne) Ignore() *SyncStatusUpsertOne { 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 *SyncStatusUpsertOne) DoNothing() *SyncStatusUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SyncStatusCreate.OnConflict // documentation for more info. func (u *SyncStatusUpsertOne) Update(set func(*SyncStatusUpsert)) *SyncStatusUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SyncStatusUpsert{UpdateSet: update}) })) return u } // SetKey sets the "key" field. func (u *SyncStatusUpsertOne) SetKey(v string) *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.SetKey(v) }) } // UpdateKey sets the "key" field to the value that was provided on create. func (u *SyncStatusUpsertOne) UpdateKey() *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.UpdateKey() }) } // SetLastOperationTime sets the "last_operation_time" field. func (u *SyncStatusUpsertOne) SetLastOperationTime(v time.Time) *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.SetLastOperationTime(v) }) } // UpdateLastOperationTime sets the "last_operation_time" field to the value that was provided on create. func (u *SyncStatusUpsertOne) UpdateLastOperationTime() *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.UpdateLastOperationTime() }) } // SetLastSyncTime sets the "last_sync_time" field. func (u *SyncStatusUpsertOne) SetLastSyncTime(v time.Time) *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.SetLastSyncTime(v) }) } // UpdateLastSyncTime sets the "last_sync_time" field to the value that was provided on create. func (u *SyncStatusUpsertOne) UpdateLastSyncTime() *SyncStatusUpsertOne { return u.Update(func(s *SyncStatusUpsert) { s.UpdateLastSyncTime() }) } // Exec executes the query. func (u *SyncStatusUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SyncStatusCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SyncStatusUpsertOne) 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 *SyncStatusUpsertOne) ID(ctx context.Context) (id int, 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 *SyncStatusUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // SyncStatusCreateBulk is the builder for creating many SyncStatus entities in bulk. type SyncStatusCreateBulk struct { config err error builders []*SyncStatusCreate conflict []sql.ConflictOption } // Save creates the SyncStatus entities in the database. func (sscb *SyncStatusCreateBulk) Save(ctx context.Context) ([]*SyncStatus, error) { if sscb.err != nil { return nil, sscb.err } specs := make([]*sqlgraph.CreateSpec, len(sscb.builders)) nodes := make([]*SyncStatus, len(sscb.builders)) mutators := make([]Mutator, len(sscb.builders)) for i := range sscb.builders { func(i int, root context.Context) { builder := sscb.builders[i] var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*SyncStatusMutation) 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, sscb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = sscb.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, sscb.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 { id := specs[i].ID.Value.(int64) nodes[i].ID = int(id) } mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, sscb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (sscb *SyncStatusCreateBulk) SaveX(ctx context.Context) []*SyncStatus { v, err := sscb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (sscb *SyncStatusCreateBulk) Exec(ctx context.Context) error { _, err := sscb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (sscb *SyncStatusCreateBulk) ExecX(ctx context.Context) { if err := sscb.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.SyncStatus.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.SyncStatusUpsert) { // SetKey(v+v). // }). // Exec(ctx) func (sscb *SyncStatusCreateBulk) OnConflict(opts ...sql.ConflictOption) *SyncStatusUpsertBulk { sscb.conflict = opts return &SyncStatusUpsertBulk{ create: sscb, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (sscb *SyncStatusCreateBulk) OnConflictColumns(columns ...string) *SyncStatusUpsertBulk { sscb.conflict = append(sscb.conflict, sql.ConflictColumns(columns...)) return &SyncStatusUpsertBulk{ create: sscb, } } // SyncStatusUpsertBulk is the builder for "upsert"-ing // a bulk of SyncStatus nodes. type SyncStatusUpsertBulk struct { create *SyncStatusCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SyncStatusUpsertBulk) UpdateNewValues() *SyncStatusUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SyncStatus.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SyncStatusUpsertBulk) Ignore() *SyncStatusUpsertBulk { 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 *SyncStatusUpsertBulk) DoNothing() *SyncStatusUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SyncStatusCreateBulk.OnConflict // documentation for more info. func (u *SyncStatusUpsertBulk) Update(set func(*SyncStatusUpsert)) *SyncStatusUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SyncStatusUpsert{UpdateSet: update}) })) return u } // SetKey sets the "key" field. func (u *SyncStatusUpsertBulk) SetKey(v string) *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.SetKey(v) }) } // UpdateKey sets the "key" field to the value that was provided on create. func (u *SyncStatusUpsertBulk) UpdateKey() *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.UpdateKey() }) } // SetLastOperationTime sets the "last_operation_time" field. func (u *SyncStatusUpsertBulk) SetLastOperationTime(v time.Time) *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.SetLastOperationTime(v) }) } // UpdateLastOperationTime sets the "last_operation_time" field to the value that was provided on create. func (u *SyncStatusUpsertBulk) UpdateLastOperationTime() *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.UpdateLastOperationTime() }) } // SetLastSyncTime sets the "last_sync_time" field. func (u *SyncStatusUpsertBulk) SetLastSyncTime(v time.Time) *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.SetLastSyncTime(v) }) } // UpdateLastSyncTime sets the "last_sync_time" field to the value that was provided on create. func (u *SyncStatusUpsertBulk) UpdateLastSyncTime() *SyncStatusUpsertBulk { return u.Update(func(s *SyncStatusUpsert) { s.UpdateLastSyncTime() }) } // Exec executes the query. func (u *SyncStatusUpsertBulk) 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 SyncStatusCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SyncStatusCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SyncStatusUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }