feat: update func
This commit is contained in:
@@ -19,6 +19,21 @@ var postsUpdateExcludeColumns = []Column{
|
||||
table.Posts.Likes,
|
||||
}
|
||||
|
||||
func (m *Posts) Update(ctx context.Context) error {
|
||||
m.UpdatedAt = time.Now()
|
||||
|
||||
stmt := table.Posts.UPDATE(table.Posts.MutableColumns.Except(table.Posts.CreatedAt, table.Posts.DeletedAt, table.Posts.Views, table.Posts.Likes)).SET(m).WHERE(table.Posts.ID.EQ(Int(m.ID))).RETURNING(table.Posts.AllColumns)
|
||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func", "Update").Errorf("error updating Posts item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "Update").Infof("Posts item updated successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Posts) CondStatus(s fields.PostStatus) Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(table.Posts.Status.EQ(Int(int64(s))))
|
||||
|
||||
Reference in New Issue
Block a user