package model import ( "context" "time" "github.com/shopspring/decimal" "github.com/uptrace/bun" ) type MaintenanceFee struct { bun.BaseModel `bun:"table:maintenance_fee,alias:m"` CreatedAndModified `bun:"extend"` Deleted `bun:"extend"` Id string `bun:",pk,notnull" json:"id"` ParkId string `bun:",notnull" json:"parkId"` Name string `bun:",notnull" json:"name"` Period string `bun:",notnull" json:"period"` Fee decimal.Decimal `bun:"type:numeric,notnull" json:"fee"` Memo *string `bun:"type:text" json:"memo"` Enabled bool `bun:",notnull" json:"enabled"` } var _ bun.BeforeAppendModelHook = (*MaintenanceFee)(nil) func (f *MaintenanceFee) BeforeAppendModel(ctx context.Context, query bun.Query) error { oprTime := time.Now() switch query.(type) { case *bun.InsertQuery: f.CreatedAt = oprTime f.LastModifiedAt = &oprTime case *bun.UpdateQuery: f.LastModifiedAt = &oprTime } return nil }