diff --git a/rpc/core/ent/dictionarydetail.go b/rpc/core/ent/dictionarydetail.go index c0cde8d..2d49225 100644 --- a/rpc/core/ent/dictionarydetail.go +++ b/rpc/core/ent/dictionarydetail.go @@ -5,6 +5,7 @@ package ent import ( "fmt" "strings" + "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -19,6 +20,10 @@ type DictionaryDetail struct { // ID of the ent. // Primary Key | 主键 ID int64 `json:"id,omitempty"` + // Create Time | 创建时间 + CreatedAt time.Time `json:"created_at,omitempty"` + // Update Time | 更新时间 + UpdatedAt time.Time `json:"updated_at,omitempty"` // Status | 状态 Status types.Status `json:"status,omitempty"` // Sort number | 排序号 @@ -70,6 +75,8 @@ func (*DictionaryDetail) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullInt64) case dictionarydetail.FieldStatus, dictionarydetail.FieldTitle, dictionarydetail.FieldKey, dictionarydetail.FieldValue: values[i] = new(sql.NullString) + case dictionarydetail.FieldCreatedAt, dictionarydetail.FieldUpdatedAt: + values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) } @@ -91,6 +98,18 @@ func (dd *DictionaryDetail) assignValues(columns []string, values []any) error { return fmt.Errorf("unexpected type %T for field id", value) } dd.ID = int64(value.Int64) + case dictionarydetail.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + dd.CreatedAt = value.Time + } + case dictionarydetail.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + dd.UpdatedAt = value.Time + } case dictionarydetail.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) @@ -174,6 +193,12 @@ func (dd *DictionaryDetail) String() string { var builder strings.Builder builder.WriteString("DictionaryDetail(") builder.WriteString(fmt.Sprintf("id=%v, ", dd.ID)) + builder.WriteString("created_at=") + builder.WriteString(dd.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(dd.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(fmt.Sprintf("%v", dd.Status)) builder.WriteString(", ") diff --git a/rpc/core/ent/dictionarydetail/dictionarydetail.go b/rpc/core/ent/dictionarydetail/dictionarydetail.go index facf1c7..540cb19 100644 --- a/rpc/core/ent/dictionarydetail/dictionarydetail.go +++ b/rpc/core/ent/dictionarydetail/dictionarydetail.go @@ -4,6 +4,7 @@ package dictionarydetail import ( "fmt" + "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -16,6 +17,10 @@ const ( Label = "dictionary_detail" // FieldID holds the string denoting the id field in the database. FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" // FieldStatus holds the string denoting the status field in the database. FieldStatus = "status" // FieldSort holds the string denoting the sort field in the database. @@ -46,6 +51,8 @@ const ( // Columns holds all SQL columns for dictionarydetail fields. var Columns = []string{ FieldID, + FieldCreatedAt, + FieldUpdatedAt, FieldStatus, FieldSort, FieldVersion, @@ -72,6 +79,12 @@ func ValidColumn(column string) bool { // import _ "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/runtime" var ( Hooks [1]ent.Hook + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time // DefaultSort holds the default value on creation for the "sort" field. DefaultSort uint32 // DefaultVersion holds the default value on creation for the "version" field. @@ -100,6 +113,16 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + // ByStatus orders the results by the status field. func ByStatus(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStatus, opts...).ToFunc() diff --git a/rpc/core/ent/dictionarydetail/where.go b/rpc/core/ent/dictionarydetail/where.go index 9de810b..9c85018 100644 --- a/rpc/core/ent/dictionarydetail/where.go +++ b/rpc/core/ent/dictionarydetail/where.go @@ -3,6 +3,8 @@ package dictionarydetail import ( + "time" + "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate" @@ -54,6 +56,16 @@ func IDLTE(id int64) predicate.DictionaryDetail { return predicate.DictionaryDetail(sql.FieldLTE(FieldID, id)) } +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldEQ(FieldUpdatedAt, v)) +} + // Sort applies equality check predicate on the "sort" field. It's identical to SortEQ. func Sort(v uint32) predicate.DictionaryDetail { return predicate.DictionaryDetail(sql.FieldEQ(FieldSort, v)) @@ -84,6 +96,86 @@ func DictionaryID(v int64) predicate.DictionaryDetail { return predicate.DictionaryDetail(sql.FieldEQ(FieldDictionaryID, v)) } +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.DictionaryDetail { + return predicate.DictionaryDetail(sql.FieldLTE(FieldUpdatedAt, v)) +} + // StatusEQ applies the EQ predicate on the "status" field. func StatusEQ(v types.Status) predicate.DictionaryDetail { vc := v diff --git a/rpc/core/ent/dictionarydetail_create.go b/rpc/core/ent/dictionarydetail_create.go index 4a89f4c..790d461 100644 --- a/rpc/core/ent/dictionarydetail_create.go +++ b/rpc/core/ent/dictionarydetail_create.go @@ -6,6 +6,7 @@ import ( "context" "errors" "fmt" + "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -23,6 +24,34 @@ type DictionaryDetailCreate struct { conflict []sql.ConflictOption } +// SetCreatedAt sets the "created_at" field. +func (ddc *DictionaryDetailCreate) SetCreatedAt(t time.Time) *DictionaryDetailCreate { + ddc.mutation.SetCreatedAt(t) + return ddc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (ddc *DictionaryDetailCreate) SetNillableCreatedAt(t *time.Time) *DictionaryDetailCreate { + if t != nil { + ddc.SetCreatedAt(*t) + } + return ddc +} + +// SetUpdatedAt sets the "updated_at" field. +func (ddc *DictionaryDetailCreate) SetUpdatedAt(t time.Time) *DictionaryDetailCreate { + ddc.mutation.SetUpdatedAt(t) + return ddc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (ddc *DictionaryDetailCreate) SetNillableUpdatedAt(t *time.Time) *DictionaryDetailCreate { + if t != nil { + ddc.SetUpdatedAt(*t) + } + return ddc +} + // SetStatus sets the "status" field. func (ddc *DictionaryDetailCreate) SetStatus(t types.Status) *DictionaryDetailCreate { ddc.mutation.SetStatus(t) @@ -145,6 +174,20 @@ func (ddc *DictionaryDetailCreate) ExecX(ctx context.Context) { // defaults sets the default values of the builder before save. func (ddc *DictionaryDetailCreate) defaults() error { + if _, ok := ddc.mutation.CreatedAt(); !ok { + if dictionarydetail.DefaultCreatedAt == nil { + return fmt.Errorf("ent: uninitialized dictionarydetail.DefaultCreatedAt (forgotten import ent/runtime?)") + } + v := dictionarydetail.DefaultCreatedAt() + ddc.mutation.SetCreatedAt(v) + } + if _, ok := ddc.mutation.UpdatedAt(); !ok { + if dictionarydetail.DefaultUpdatedAt == nil { + return fmt.Errorf("ent: uninitialized dictionarydetail.DefaultUpdatedAt (forgotten import ent/runtime?)") + } + v := dictionarydetail.DefaultUpdatedAt() + ddc.mutation.SetUpdatedAt(v) + } if _, ok := ddc.mutation.Status(); !ok { v := dictionarydetail.DefaultStatus ddc.mutation.SetStatus(v) @@ -169,6 +212,12 @@ func (ddc *DictionaryDetailCreate) defaults() error { // check runs all checks and user-defined validators on the builder. func (ddc *DictionaryDetailCreate) check() error { + if _, ok := ddc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DictionaryDetail.created_at"`)} + } + if _, ok := ddc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DictionaryDetail.updated_at"`)} + } if _, ok := ddc.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "DictionaryDetail.status"`)} } @@ -231,6 +280,14 @@ func (ddc *DictionaryDetailCreate) createSpec() (*DictionaryDetail, *sqlgraph.Cr _node.ID = id _spec.ID.Value = id } + if value, ok := ddc.mutation.CreatedAt(); ok { + _spec.SetField(dictionarydetail.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := ddc.mutation.UpdatedAt(); ok { + _spec.SetField(dictionarydetail.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } if value, ok := ddc.mutation.Status(); ok { _spec.SetField(dictionarydetail.FieldStatus, field.TypeEnum, value) _node.Status = value @@ -279,7 +336,7 @@ func (ddc *DictionaryDetailCreate) createSpec() (*DictionaryDetail, *sqlgraph.Cr // of the `INSERT` statement. For example: // // client.DictionaryDetail.Create(). -// SetStatus(v). +// SetCreatedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -288,7 +345,7 @@ func (ddc *DictionaryDetailCreate) createSpec() (*DictionaryDetail, *sqlgraph.Cr // // Override some of the fields with custom // // update values. // Update(func(u *ent.DictionaryDetailUpsert) { -// SetStatus(v+v). +// SetCreatedAt(v+v). // }). // Exec(ctx) func (ddc *DictionaryDetailCreate) OnConflict(opts ...sql.ConflictOption) *DictionaryDetailUpsertOne { @@ -324,6 +381,18 @@ type ( } ) +// SetUpdatedAt sets the "updated_at" field. +func (u *DictionaryDetailUpsert) SetUpdatedAt(v time.Time) *DictionaryDetailUpsert { + u.Set(dictionarydetail.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *DictionaryDetailUpsert) UpdateUpdatedAt() *DictionaryDetailUpsert { + u.SetExcluded(dictionarydetail.FieldUpdatedAt) + return u +} + // SetStatus sets the "status" field. func (u *DictionaryDetailUpsert) SetStatus(v types.Status) *DictionaryDetailUpsert { u.Set(dictionarydetail.FieldStatus, v) @@ -437,6 +506,9 @@ func (u *DictionaryDetailUpsertOne) UpdateNewValues() *DictionaryDetailUpsertOne if _, exists := u.create.mutation.ID(); exists { s.SetIgnore(dictionarydetail.FieldID) } + if _, exists := u.create.mutation.CreatedAt(); exists { + s.SetIgnore(dictionarydetail.FieldCreatedAt) + } })) return u } @@ -468,6 +540,20 @@ func (u *DictionaryDetailUpsertOne) Update(set func(*DictionaryDetailUpsert)) *D return u } +// SetUpdatedAt sets the "updated_at" field. +func (u *DictionaryDetailUpsertOne) SetUpdatedAt(v time.Time) *DictionaryDetailUpsertOne { + return u.Update(func(s *DictionaryDetailUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *DictionaryDetailUpsertOne) UpdateUpdatedAt() *DictionaryDetailUpsertOne { + return u.Update(func(s *DictionaryDetailUpsert) { + s.UpdateUpdatedAt() + }) +} + // SetStatus sets the "status" field. func (u *DictionaryDetailUpsertOne) SetStatus(v types.Status) *DictionaryDetailUpsertOne { return u.Update(func(s *DictionaryDetailUpsert) { @@ -711,7 +797,7 @@ func (ddcb *DictionaryDetailCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.DictionaryDetailUpsert) { -// SetStatus(v+v). +// SetCreatedAt(v+v). // }). // Exec(ctx) func (ddcb *DictionaryDetailCreateBulk) OnConflict(opts ...sql.ConflictOption) *DictionaryDetailUpsertBulk { @@ -758,6 +844,9 @@ func (u *DictionaryDetailUpsertBulk) UpdateNewValues() *DictionaryDetailUpsertBu if _, exists := b.mutation.ID(); exists { s.SetIgnore(dictionarydetail.FieldID) } + if _, exists := b.mutation.CreatedAt(); exists { + s.SetIgnore(dictionarydetail.FieldCreatedAt) + } } })) return u @@ -790,6 +879,20 @@ func (u *DictionaryDetailUpsertBulk) Update(set func(*DictionaryDetailUpsert)) * return u } +// SetUpdatedAt sets the "updated_at" field. +func (u *DictionaryDetailUpsertBulk) SetUpdatedAt(v time.Time) *DictionaryDetailUpsertBulk { + return u.Update(func(s *DictionaryDetailUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *DictionaryDetailUpsertBulk) UpdateUpdatedAt() *DictionaryDetailUpsertBulk { + return u.Update(func(s *DictionaryDetailUpsert) { + s.UpdateUpdatedAt() + }) +} + // SetStatus sets the "status" field. func (u *DictionaryDetailUpsertBulk) SetStatus(v types.Status) *DictionaryDetailUpsertBulk { return u.Update(func(s *DictionaryDetailUpsert) { diff --git a/rpc/core/ent/dictionarydetail_query.go b/rpc/core/ent/dictionarydetail_query.go index 9c51b4b..d16fb7a 100644 --- a/rpc/core/ent/dictionarydetail_query.go +++ b/rpc/core/ent/dictionarydetail_query.go @@ -298,12 +298,12 @@ func (ddq *DictionaryDetailQuery) WithDictionary(opts ...func(*DictionaryQuery)) // Example: // // var v []struct { -// Status types.Status `json:"status,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // Count int `json:"count,omitempty"` // } // // client.DictionaryDetail.Query(). -// GroupBy(dictionarydetail.FieldStatus). +// GroupBy(dictionarydetail.FieldCreatedAt). // Aggregate(ent.Count()). // Scan(ctx, &v) func (ddq *DictionaryDetailQuery) GroupBy(field string, fields ...string) *DictionaryDetailGroupBy { @@ -321,11 +321,11 @@ func (ddq *DictionaryDetailQuery) GroupBy(field string, fields ...string) *Dicti // Example: // // var v []struct { -// Status types.Status `json:"status,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // } // // client.DictionaryDetail.Query(). -// Select(dictionarydetail.FieldStatus). +// Select(dictionarydetail.FieldCreatedAt). // Scan(ctx, &v) func (ddq *DictionaryDetailQuery) Select(fields ...string) *DictionaryDetailSelect { ddq.ctx.Fields = append(ddq.ctx.Fields, fields...) diff --git a/rpc/core/ent/dictionarydetail_update.go b/rpc/core/ent/dictionarydetail_update.go index 94b4b45..d01bef5 100644 --- a/rpc/core/ent/dictionarydetail_update.go +++ b/rpc/core/ent/dictionarydetail_update.go @@ -6,6 +6,7 @@ import ( "context" "errors" "fmt" + "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -30,6 +31,12 @@ func (ddu *DictionaryDetailUpdate) Where(ps ...predicate.DictionaryDetail) *Dict return ddu } +// SetUpdatedAt sets the "updated_at" field. +func (ddu *DictionaryDetailUpdate) SetUpdatedAt(t time.Time) *DictionaryDetailUpdate { + ddu.mutation.SetUpdatedAt(t) + return ddu +} + // SetStatus sets the "status" field. func (ddu *DictionaryDetailUpdate) SetStatus(t types.Status) *DictionaryDetailUpdate { ddu.mutation.SetStatus(t) @@ -128,6 +135,9 @@ func (ddu *DictionaryDetailUpdate) ClearDictionary() *DictionaryDetailUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (ddu *DictionaryDetailUpdate) Save(ctx context.Context) (int, error) { + if err := ddu.defaults(); err != nil { + return 0, err + } return withHooks(ctx, ddu.sqlSave, ddu.mutation, ddu.hooks) } @@ -153,6 +163,18 @@ func (ddu *DictionaryDetailUpdate) ExecX(ctx context.Context) { } } +// defaults sets the default values of the builder before save. +func (ddu *DictionaryDetailUpdate) defaults() error { + if _, ok := ddu.mutation.UpdatedAt(); !ok { + if dictionarydetail.UpdateDefaultUpdatedAt == nil { + return fmt.Errorf("ent: uninitialized dictionarydetail.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") + } + v := dictionarydetail.UpdateDefaultUpdatedAt() + ddu.mutation.SetUpdatedAt(v) + } + return nil +} + // check runs all checks and user-defined validators on the builder. func (ddu *DictionaryDetailUpdate) check() error { if v, ok := ddu.mutation.Status(); ok { @@ -184,6 +206,9 @@ func (ddu *DictionaryDetailUpdate) sqlSave(ctx context.Context) (n int, err erro } } } + if value, ok := ddu.mutation.UpdatedAt(); ok { + _spec.SetField(dictionarydetail.FieldUpdatedAt, field.TypeTime, value) + } if value, ok := ddu.mutation.Status(); ok { _spec.SetField(dictionarydetail.FieldStatus, field.TypeEnum, value) } @@ -259,6 +284,12 @@ type DictionaryDetailUpdateOne struct { modifiers []func(*sql.UpdateBuilder) } +// SetUpdatedAt sets the "updated_at" field. +func (dduo *DictionaryDetailUpdateOne) SetUpdatedAt(t time.Time) *DictionaryDetailUpdateOne { + dduo.mutation.SetUpdatedAt(t) + return dduo +} + // SetStatus sets the "status" field. func (dduo *DictionaryDetailUpdateOne) SetStatus(t types.Status) *DictionaryDetailUpdateOne { dduo.mutation.SetStatus(t) @@ -370,6 +401,9 @@ func (dduo *DictionaryDetailUpdateOne) Select(field string, fields ...string) *D // Save executes the query and returns the updated DictionaryDetail entity. func (dduo *DictionaryDetailUpdateOne) Save(ctx context.Context) (*DictionaryDetail, error) { + if err := dduo.defaults(); err != nil { + return nil, err + } return withHooks(ctx, dduo.sqlSave, dduo.mutation, dduo.hooks) } @@ -395,6 +429,18 @@ func (dduo *DictionaryDetailUpdateOne) ExecX(ctx context.Context) { } } +// defaults sets the default values of the builder before save. +func (dduo *DictionaryDetailUpdateOne) defaults() error { + if _, ok := dduo.mutation.UpdatedAt(); !ok { + if dictionarydetail.UpdateDefaultUpdatedAt == nil { + return fmt.Errorf("ent: uninitialized dictionarydetail.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") + } + v := dictionarydetail.UpdateDefaultUpdatedAt() + dduo.mutation.SetUpdatedAt(v) + } + return nil +} + // check runs all checks and user-defined validators on the builder. func (dduo *DictionaryDetailUpdateOne) check() error { if v, ok := dduo.mutation.Status(); ok { @@ -443,6 +489,9 @@ func (dduo *DictionaryDetailUpdateOne) sqlSave(ctx context.Context) (_node *Dict } } } + if value, ok := dduo.mutation.UpdatedAt(); ok { + _spec.SetField(dictionarydetail.FieldUpdatedAt, field.TypeTime, value) + } if value, ok := dduo.mutation.Status(); ok { _spec.SetField(dictionarydetail.FieldStatus, field.TypeEnum, value) } diff --git a/rpc/core/ent/migrate/schema.go b/rpc/core/ent/migrate/schema.go index 2fb9bce..d120f86 100644 --- a/rpc/core/ent/migrate/schema.go +++ b/rpc/core/ent/migrate/schema.go @@ -63,6 +63,8 @@ var ( // SysDictionaryDetailsColumns holds the columns for the "sys_dictionary_details" table. SysDictionaryDetailsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Comment: "Primary Key | 主键"}, + {Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建时间", SchemaType: map[string]string{"mysql": "datetime"}}, + {Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 更新时间", SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "status", Type: field.TypeEnum, Comment: "Status | 状态", Enums: []string{"Normal", "Pending", "Disabled", "Locked"}, Default: "Normal", SchemaType: map[string]string{"mysql": "varchar(32)"}}, {Name: "sort", Type: field.TypeUint32, Comment: "Sort number | 排序号", Default: 1}, {Name: "version", Type: field.TypeInt64, Comment: "optimistic lock | 乐观锁", Default: 1}, @@ -80,7 +82,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "sys_dictionary_details_sys_dictionary_details", - Columns: []*schema.Column{SysDictionaryDetailsColumns[7]}, + Columns: []*schema.Column{SysDictionaryDetailsColumns[9]}, RefColumns: []*schema.Column{SysDictionaryColumns[0]}, OnDelete: schema.Cascade, }, @@ -89,17 +91,17 @@ var ( { Name: "dictionarydetail_dictionary_id_key", Unique: true, - Columns: []*schema.Column{SysDictionaryDetailsColumns[7], SysDictionaryDetailsColumns[5]}, + Columns: []*schema.Column{SysDictionaryDetailsColumns[9], SysDictionaryDetailsColumns[7]}, }, { Name: "dictionarydetail_key", Unique: false, - Columns: []*schema.Column{SysDictionaryDetailsColumns[5]}, + Columns: []*schema.Column{SysDictionaryDetailsColumns[7]}, }, { Name: "dictionarydetail_title", Unique: false, - Columns: []*schema.Column{SysDictionaryDetailsColumns[4]}, + Columns: []*schema.Column{SysDictionaryDetailsColumns[6]}, }, }, } diff --git a/rpc/core/ent/mutation.go b/rpc/core/ent/mutation.go index 81362a1..cad460c 100644 --- a/rpc/core/ent/mutation.go +++ b/rpc/core/ent/mutation.go @@ -1933,6 +1933,8 @@ type DictionaryDetailMutation struct { op Op typ string id *int64 + created_at *time.Time + updated_at *time.Time status *types.Status sort *uint32 addsort *int32 @@ -2053,6 +2055,78 @@ func (m *DictionaryDetailMutation) IDs(ctx context.Context) ([]int64, error) { } } +// SetCreatedAt sets the "created_at" field. +func (m *DictionaryDetailMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *DictionaryDetailMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the DictionaryDetail entity. +// If the DictionaryDetail object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *DictionaryDetailMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *DictionaryDetailMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *DictionaryDetailMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *DictionaryDetailMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the DictionaryDetail entity. +// If the DictionaryDetail object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *DictionaryDetailMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *DictionaryDetailMutation) ResetUpdatedAt() { + m.updated_at = nil +} + // SetStatus sets the "status" field. func (m *DictionaryDetailMutation) SetStatus(t types.Status) { m.status = &t @@ -2405,7 +2479,13 @@ func (m *DictionaryDetailMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *DictionaryDetailMutation) Fields() []string { - fields := make([]string, 0, 7) + fields := make([]string, 0, 9) + if m.created_at != nil { + fields = append(fields, dictionarydetail.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, dictionarydetail.FieldUpdatedAt) + } if m.status != nil { fields = append(fields, dictionarydetail.FieldStatus) } @@ -2435,6 +2515,10 @@ func (m *DictionaryDetailMutation) Fields() []string { // schema. func (m *DictionaryDetailMutation) Field(name string) (ent.Value, bool) { switch name { + case dictionarydetail.FieldCreatedAt: + return m.CreatedAt() + case dictionarydetail.FieldUpdatedAt: + return m.UpdatedAt() case dictionarydetail.FieldStatus: return m.Status() case dictionarydetail.FieldSort: @@ -2458,6 +2542,10 @@ func (m *DictionaryDetailMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *DictionaryDetailMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { + case dictionarydetail.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case dictionarydetail.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) case dictionarydetail.FieldStatus: return m.OldStatus(ctx) case dictionarydetail.FieldSort: @@ -2481,6 +2569,20 @@ func (m *DictionaryDetailMutation) OldField(ctx context.Context, name string) (e // type. func (m *DictionaryDetailMutation) SetField(name string, value ent.Value) error { switch name { + case dictionarydetail.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case dictionarydetail.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil case dictionarydetail.FieldStatus: v, ok := value.(types.Status) if !ok { @@ -2606,6 +2708,12 @@ func (m *DictionaryDetailMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *DictionaryDetailMutation) ResetField(name string) error { switch name { + case dictionarydetail.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case dictionarydetail.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil case dictionarydetail.FieldStatus: m.ResetStatus() return nil diff --git a/rpc/core/ent/runtime/runtime.go b/rpc/core/ent/runtime/runtime.go index 5f58f8f..b91132d 100644 --- a/rpc/core/ent/runtime/runtime.go +++ b/rpc/core/ent/runtime/runtime.go @@ -86,8 +86,8 @@ func init() { // dictionary.DefaultID holds the default value on creation for the id field. dictionary.DefaultID = dictionaryDescID.Default.(func() int64) dictionarydetailMixin := schema.DictionaryDetail{}.Mixin() - dictionarydetailMixinHooks3 := dictionarydetailMixin[3].Hooks() - dictionarydetail.Hooks[0] = dictionarydetailMixinHooks3[0] + dictionarydetailMixinHooks4 := dictionarydetailMixin[4].Hooks() + dictionarydetail.Hooks[0] = dictionarydetailMixinHooks4[0] dictionarydetailMixinFields0 := dictionarydetailMixin[0].Fields() _ = dictionarydetailMixinFields0 dictionarydetailMixinFields1 := dictionarydetailMixin[1].Fields() @@ -96,14 +96,26 @@ func init() { _ = dictionarydetailMixinFields2 dictionarydetailMixinFields3 := dictionarydetailMixin[3].Fields() _ = dictionarydetailMixinFields3 + dictionarydetailMixinFields4 := dictionarydetailMixin[4].Fields() + _ = dictionarydetailMixinFields4 dictionarydetailFields := schema.DictionaryDetail{}.Fields() _ = dictionarydetailFields + // dictionarydetailDescCreatedAt is the schema descriptor for created_at field. + dictionarydetailDescCreatedAt := dictionarydetailMixinFields1[0].Descriptor() + // dictionarydetail.DefaultCreatedAt holds the default value on creation for the created_at field. + dictionarydetail.DefaultCreatedAt = dictionarydetailDescCreatedAt.Default.(func() time.Time) + // dictionarydetailDescUpdatedAt is the schema descriptor for updated_at field. + dictionarydetailDescUpdatedAt := dictionarydetailMixinFields1[1].Descriptor() + // dictionarydetail.DefaultUpdatedAt holds the default value on creation for the updated_at field. + dictionarydetail.DefaultUpdatedAt = dictionarydetailDescUpdatedAt.Default.(func() time.Time) + // dictionarydetail.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + dictionarydetail.UpdateDefaultUpdatedAt = dictionarydetailDescUpdatedAt.UpdateDefault.(func() time.Time) // dictionarydetailDescSort is the schema descriptor for sort field. - dictionarydetailDescSort := dictionarydetailMixinFields2[0].Descriptor() + dictionarydetailDescSort := dictionarydetailMixinFields3[0].Descriptor() // dictionarydetail.DefaultSort holds the default value on creation for the sort field. dictionarydetail.DefaultSort = dictionarydetailDescSort.Default.(uint32) // dictionarydetailDescVersion is the schema descriptor for version field. - dictionarydetailDescVersion := dictionarydetailMixinFields3[0].Descriptor() + dictionarydetailDescVersion := dictionarydetailMixinFields4[0].Descriptor() // dictionarydetail.DefaultVersion holds the default value on creation for the version field. dictionarydetail.DefaultVersion = dictionarydetailDescVersion.Default.(int64) // dictionarydetailDescID is the schema descriptor for id field. diff --git a/rpc/core/ent/schema/dictionary_detail.go b/rpc/core/ent/schema/dictionary_detail.go index 6a09a2e..de56b72 100644 --- a/rpc/core/ent/schema/dictionary_detail.go +++ b/rpc/core/ent/schema/dictionary_detail.go @@ -31,6 +31,7 @@ func (DictionaryDetail) Fields() []ent.Field { func (DictionaryDetail) Mixin() []ent.Mixin { return []ent.Mixin{ mixins.NewDistributedIDMixin(func() int64 { return nrandom.SnowflakeId() }), + mixins.TimeMixin{}, mixins.StatusMixin{}, mixins.SortMixin{}, mixins.OptimisticLockMixin{}, diff --git a/rpc/core/ent/set_not_nil.go b/rpc/core/ent/set_not_nil.go index b338f3f..1276f70 100644 --- a/rpc/core/ent/set_not_nil.go +++ b/rpc/core/ent/set_not_nil.go @@ -320,6 +320,30 @@ func (d *DictionaryCreate) SetNotNilDescription(value *string) *DictionaryCreate return d } +// set field if value's pointer is not nil. +func (dd *DictionaryDetailUpdate) SetNotNilUpdatedAt(value *time.Time) *DictionaryDetailUpdate { + if value != nil { + return dd.SetUpdatedAt(*value) + } + return dd +} + +// set field if value's pointer is not nil. +func (dd *DictionaryDetailUpdateOne) SetNotNilUpdatedAt(value *time.Time) *DictionaryDetailUpdateOne { + if value != nil { + return dd.SetUpdatedAt(*value) + } + return dd +} + +// set field if value's pointer is not nil. +func (dd *DictionaryDetailCreate) SetNotNilUpdatedAt(value *time.Time) *DictionaryDetailCreate { + if value != nil { + return dd.SetUpdatedAt(*value) + } + return dd +} + // set field if value's pointer is not nil. func (dd *DictionaryDetailUpdate) SetNotNilStatus(value *types.Status) *DictionaryDetailUpdate { if value != nil {