896 lines
26 KiB
Go
896 lines
26 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_wms/ent/eventlog"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// EventLogCreate is the builder for creating a EventLog entity.
|
||
|
|
type EventLogCreate struct {
|
||
|
|
config
|
||
|
|
mutation *EventLogMutation
|
||
|
|
hooks []Hook
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEventType sets the "event_type" field.
|
||
|
|
func (_c *EventLogCreate) SetEventType(v string) *EventLogCreate {
|
||
|
|
_c.mutation.SetEventType(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_c *EventLogCreate) SetOperator(v string) *EventLogCreate {
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_c *EventLogCreate) SetNillableOperator(v *string) *EventLogCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityType sets the "entity_type" field.
|
||
|
|
func (_c *EventLogCreate) SetEntityType(v string) *EventLogCreate {
|
||
|
|
_c.mutation.SetEntityType(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableEntityType sets the "entity_type" field if the given value is not nil.
|
||
|
|
func (_c *EventLogCreate) SetNillableEntityType(v *string) *EventLogCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetEntityType(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityID sets the "entity_id" field.
|
||
|
|
func (_c *EventLogCreate) SetEntityID(v string) *EventLogCreate {
|
||
|
|
_c.mutation.SetEntityID(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableEntityID sets the "entity_id" field if the given value is not nil.
|
||
|
|
func (_c *EventLogCreate) SetNillableEntityID(v *string) *EventLogCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetEntityID(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (_c *EventLogCreate) SetDescription(v string) *EventLogCreate {
|
||
|
|
_c.mutation.SetDescription(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||
|
|
func (_c *EventLogCreate) SetNillableDescription(v *string) *EventLogCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetDescription(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPayload sets the "payload" field.
|
||
|
|
func (_c *EventLogCreate) SetPayload(v map[string]interface{}) *EventLogCreate {
|
||
|
|
_c.mutation.SetPayload(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (_c *EventLogCreate) SetCreatedAt(v int64) *EventLogCreate {
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||
|
|
func (_c *EventLogCreate) SetNillableCreatedAt(v *int64) *EventLogCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetCreatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the EventLogMutation object of the builder.
|
||
|
|
func (_c *EventLogCreate) Mutation() *EventLogMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the EventLog in the database.
|
||
|
|
func (_c *EventLogCreate) Save(ctx context.Context) (*EventLog, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *EventLogCreate) SaveX(ctx context.Context) *EventLog {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *EventLogCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *EventLogCreate) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// defaults sets the default values of the builder before save.
|
||
|
|
func (_c *EventLogCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
v := eventlog.DefaultOperator
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.EntityType(); !ok {
|
||
|
|
v := eventlog.DefaultEntityType
|
||
|
|
_c.mutation.SetEntityType(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.EntityID(); !ok {
|
||
|
|
v := eventlog.DefaultEntityID
|
||
|
|
_c.mutation.SetEntityID(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Description(); !ok {
|
||
|
|
v := eventlog.DefaultDescription
|
||
|
|
_c.mutation.SetDescription(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
v := eventlog.DefaultCreatedAt()
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *EventLogCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.EventType(); !ok {
|
||
|
|
return &ValidationError{Name: "event_type", err: errors.New(`ent: missing required field "EventLog.event_type"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.EventType(); ok {
|
||
|
|
if err := eventlog.EventTypeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "event_type", err: fmt.Errorf(`ent: validator failed for field "EventLog.event_type": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "EventLog.operator"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Operator(); ok {
|
||
|
|
if err := eventlog.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "EventLog.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.EntityType(); !ok {
|
||
|
|
return &ValidationError{Name: "entity_type", err: errors.New(`ent: missing required field "EventLog.entity_type"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.EntityType(); ok {
|
||
|
|
if err := eventlog.EntityTypeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "entity_type", err: fmt.Errorf(`ent: validator failed for field "EventLog.entity_type": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.EntityID(); !ok {
|
||
|
|
return &ValidationError{Name: "entity_id", err: errors.New(`ent: missing required field "EventLog.entity_id"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.EntityID(); ok {
|
||
|
|
if err := eventlog.EntityIDValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "entity_id", err: fmt.Errorf(`ent: validator failed for field "EventLog.entity_id": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Description(); !ok {
|
||
|
|
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "EventLog.description"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "EventLog.created_at"`)}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *EventLogCreate) sqlSave(ctx context.Context) (*EventLog, error) {
|
||
|
|
if err := _c.check(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
_node, _spec := _c.createSpec()
|
||
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||
|
|
if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
id := _spec.ID.Value.(int64)
|
||
|
|
_node.ID = int(id)
|
||
|
|
_c.mutation.id = &_node.ID
|
||
|
|
_c.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *EventLogCreate) createSpec() (*EventLog, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &EventLog{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(eventlog.Table, sqlgraph.NewFieldSpec(eventlog.FieldID, field.TypeInt))
|
||
|
|
)
|
||
|
|
_spec.OnConflict = _c.conflict
|
||
|
|
if value, ok := _c.mutation.EventType(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldEventType, field.TypeString, value)
|
||
|
|
_node.EventType = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldOperator, field.TypeString, value)
|
||
|
|
_node.Operator = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.EntityType(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldEntityType, field.TypeString, value)
|
||
|
|
_node.EntityType = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.EntityID(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldEntityID, field.TypeString, value)
|
||
|
|
_node.EntityID = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Description(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldDescription, field.TypeString, value)
|
||
|
|
_node.Description = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Payload(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldPayload, field.TypeJSON, value)
|
||
|
|
_node.Payload = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||
|
|
_spec.SetField(eventlog.FieldCreatedAt, field.TypeInt64, value)
|
||
|
|
_node.CreatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||
|
|
// of the `INSERT` statement. For example:
|
||
|
|
//
|
||
|
|
// client.EventLog.Create().
|
||
|
|
// SetEventType(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.EventLogUpsert) {
|
||
|
|
// SetEventType(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *EventLogCreate) OnConflict(opts ...sql.ConflictOption) *EventLogUpsertOne {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &EventLogUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.EventLog.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *EventLogCreate) OnConflictColumns(columns ...string) *EventLogUpsertOne {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &EventLogUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type (
|
||
|
|
// EventLogUpsertOne is the builder for "upsert"-ing
|
||
|
|
// one EventLog node.
|
||
|
|
EventLogUpsertOne struct {
|
||
|
|
create *EventLogCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// EventLogUpsert is the "OnConflict" setter.
|
||
|
|
EventLogUpsert struct {
|
||
|
|
*sql.UpdateSet
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
// SetEventType sets the "event_type" field.
|
||
|
|
func (u *EventLogUpsert) SetEventType(v string) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldEventType, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEventType sets the "event_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateEventType() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldEventType)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (u *EventLogUpsert) SetOperator(v string) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldOperator, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateOperator() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldOperator)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityType sets the "entity_type" field.
|
||
|
|
func (u *EventLogUpsert) SetEntityType(v string) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldEntityType, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityType sets the "entity_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateEntityType() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldEntityType)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityID sets the "entity_id" field.
|
||
|
|
func (u *EventLogUpsert) SetEntityID(v string) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldEntityID, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityID sets the "entity_id" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateEntityID() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldEntityID)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (u *EventLogUpsert) SetDescription(v string) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldDescription, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateDescription() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldDescription)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPayload sets the "payload" field.
|
||
|
|
func (u *EventLogUpsert) SetPayload(v map[string]interface{}) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldPayload, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePayload sets the "payload" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdatePayload() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldPayload)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPayload clears the value of the "payload" field.
|
||
|
|
func (u *EventLogUpsert) ClearPayload() *EventLogUpsert {
|
||
|
|
u.SetNull(eventlog.FieldPayload)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *EventLogUpsert) SetCreatedAt(v int64) *EventLogUpsert {
|
||
|
|
u.Set(eventlog.FieldCreatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsert) UpdateCreatedAt() *EventLogUpsert {
|
||
|
|
u.SetExcluded(eventlog.FieldCreatedAt)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *EventLogUpsert) AddCreatedAt(v int64) *EventLogUpsert {
|
||
|
|
u.Add(eventlog.FieldCreatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.EventLog.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *EventLogUpsertOne) UpdateNewValues() *EventLogUpsertOne {
|
||
|
|
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.EventLog.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *EventLogUpsertOne) Ignore() *EventLogUpsertOne {
|
||
|
|
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 *EventLogUpsertOne) DoNothing() *EventLogUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the EventLogCreate.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *EventLogUpsertOne) Update(set func(*EventLogUpsert)) *EventLogUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&EventLogUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEventType sets the "event_type" field.
|
||
|
|
func (u *EventLogUpsertOne) SetEventType(v string) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEventType(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEventType sets the "event_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateEventType() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEventType()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (u *EventLogUpsertOne) SetOperator(v string) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetOperator(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateOperator() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateOperator()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityType sets the "entity_type" field.
|
||
|
|
func (u *EventLogUpsertOne) SetEntityType(v string) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEntityType(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityType sets the "entity_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateEntityType() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEntityType()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityID sets the "entity_id" field.
|
||
|
|
func (u *EventLogUpsertOne) SetEntityID(v string) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEntityID(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityID sets the "entity_id" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateEntityID() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEntityID()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (u *EventLogUpsertOne) SetDescription(v string) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetDescription(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateDescription() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateDescription()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPayload sets the "payload" field.
|
||
|
|
func (u *EventLogUpsertOne) SetPayload(v map[string]interface{}) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetPayload(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePayload sets the "payload" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdatePayload() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdatePayload()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPayload clears the value of the "payload" field.
|
||
|
|
func (u *EventLogUpsertOne) ClearPayload() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.ClearPayload()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *EventLogUpsertOne) SetCreatedAt(v int64) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *EventLogUpsertOne) AddCreatedAt(v int64) *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.AddCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertOne) UpdateCreatedAt() *EventLogUpsertOne {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateCreatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *EventLogUpsertOne) Exec(ctx context.Context) error {
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for EventLogCreate.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *EventLogUpsertOne) 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 *EventLogUpsertOne) 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 *EventLogUpsertOne) IDX(ctx context.Context) int {
|
||
|
|
id, err := u.ID(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
|
||
|
|
// EventLogCreateBulk is the builder for creating many EventLog entities in bulk.
|
||
|
|
type EventLogCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*EventLogCreate
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the EventLog entities in the database.
|
||
|
|
func (_c *EventLogCreateBulk) Save(ctx context.Context) ([]*EventLog, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*EventLog, len(_c.builders))
|
||
|
|
mutators := make([]Mutator, len(_c.builders))
|
||
|
|
for i := range _c.builders {
|
||
|
|
func(i int, root context.Context) {
|
||
|
|
builder := _c.builders[i]
|
||
|
|
builder.defaults()
|
||
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
|
mutation, ok := m.(*EventLogMutation)
|
||
|
|
if !ok {
|
||
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||
|
|
}
|
||
|
|
if err := builder.check(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
builder.mutation = mutation
|
||
|
|
var err error
|
||
|
|
nodes[i], specs[i] = builder.createSpec()
|
||
|
|
if i < len(mutators)-1 {
|
||
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||
|
|
} else {
|
||
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||
|
|
spec.OnConflict = _c.conflict
|
||
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
||
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||
|
|
if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
mutation.id = &nodes[i].ID
|
||
|
|
if specs[i].ID.Value != nil {
|
||
|
|
id := specs[i].ID.Value.(int64)
|
||
|
|
nodes[i].ID = int(id)
|
||
|
|
}
|
||
|
|
mutation.done = true
|
||
|
|
return nodes[i], nil
|
||
|
|
})
|
||
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||
|
|
mut = builder.hooks[i](mut)
|
||
|
|
}
|
||
|
|
mutators[i] = mut
|
||
|
|
}(i, ctx)
|
||
|
|
}
|
||
|
|
if len(mutators) > 0 {
|
||
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nodes, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_c *EventLogCreateBulk) SaveX(ctx context.Context) []*EventLog {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *EventLogCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *EventLogCreateBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||
|
|
// of the `INSERT` statement. For example:
|
||
|
|
//
|
||
|
|
// client.EventLog.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.EventLogUpsert) {
|
||
|
|
// SetEventType(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *EventLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *EventLogUpsertBulk {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &EventLogUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.EventLog.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *EventLogCreateBulk) OnConflictColumns(columns ...string) *EventLogUpsertBulk {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &EventLogUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// EventLogUpsertBulk is the builder for "upsert"-ing
|
||
|
|
// a bulk of EventLog nodes.
|
||
|
|
type EventLogUpsertBulk struct {
|
||
|
|
create *EventLogCreateBulk
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
||
|
|
// were set on create. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.EventLog.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *EventLogUpsertBulk) UpdateNewValues() *EventLogUpsertBulk {
|
||
|
|
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.EventLog.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *EventLogUpsertBulk) Ignore() *EventLogUpsertBulk {
|
||
|
|
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 *EventLogUpsertBulk) DoNothing() *EventLogUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the EventLogCreateBulk.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *EventLogUpsertBulk) Update(set func(*EventLogUpsert)) *EventLogUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&EventLogUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEventType sets the "event_type" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetEventType(v string) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEventType(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEventType sets the "event_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateEventType() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEventType()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetOperator(v string) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetOperator(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateOperator() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateOperator()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityType sets the "entity_type" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetEntityType(v string) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEntityType(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityType sets the "entity_type" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateEntityType() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEntityType()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEntityID sets the "entity_id" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetEntityID(v string) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetEntityID(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateEntityID sets the "entity_id" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateEntityID() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateEntityID()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetDescription(v string) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetDescription(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateDescription() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateDescription()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPayload sets the "payload" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetPayload(v map[string]interface{}) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetPayload(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePayload sets the "payload" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdatePayload() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdatePayload()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPayload clears the value of the "payload" field.
|
||
|
|
func (u *EventLogUpsertBulk) ClearPayload() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.ClearPayload()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *EventLogUpsertBulk) SetCreatedAt(v int64) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.SetCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *EventLogUpsertBulk) AddCreatedAt(v int64) *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.AddCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *EventLogUpsertBulk) UpdateCreatedAt() *EventLogUpsertBulk {
|
||
|
|
return u.Update(func(s *EventLogUpsert) {
|
||
|
|
s.UpdateCreatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *EventLogUpsertBulk) 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 EventLogCreateBulk instead", i)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for EventLogCreateBulk.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *EventLogUpsertBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := u.create.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|