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
+27
View File
@@ -0,0 +1,27 @@
package ersteller_ent
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
)
// TimeMixin implements the ent.Mixin for sharing
// time fields with package schemas.
type TimeMixin struct {
mixin.Schema
}
// Fields of the TimeMixin.
func (TimeMixin) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Default(time.Now).
Immutable(),
field.Time("updated_at").
Default(time.Now).
UpdateDefault(time.Now),
}
}