Add a mixin for time fields

This commit is contained in:
Achim Rohn
2025-09-12 09:31:21 +02:00
parent 6cbd155db6
commit a817f7550b
25 changed files with 1086 additions and 336 deletions
+37
View File
@@ -10,6 +10,7 @@ import (
"ersteller-lib/schema/ent/example/ent/todo"
"ersteller-lib/schema/ent/example/ent/user"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -29,6 +30,12 @@ func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field.
func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
_u.mutation.SetName(v)
@@ -122,6 +129,7 @@ func (_u *GroupUpdate) RemoveTodos(v ...*Todo) *GroupUpdate {
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *GroupUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
@@ -147,6 +155,14 @@ func (_u *GroupUpdate) ExecX(ctx context.Context) {
}
}
// defaults sets the default values of the builder before save.
func (_u *GroupUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := group.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
@@ -156,6 +172,9 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(group.FieldName, field.TypeString, value)
}
@@ -269,6 +288,12 @@ type GroupUpdateOne struct {
mutation *GroupMutation
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field.
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
_u.mutation.SetName(v)
@@ -375,6 +400,7 @@ func (_u *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne
// Save executes the query and returns the updated Group entity.
func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
@@ -400,6 +426,14 @@ func (_u *GroupUpdateOne) ExecX(ctx context.Context) {
}
}
// defaults sets the default values of the builder before save.
func (_u *GroupUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := group.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
@@ -426,6 +460,9 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(group.FieldName, field.TypeString, value)
}