feat: update func

This commit is contained in:
Rogee
2025-05-23 23:50:26 +08:00
parent 1166a5c949
commit f28bc7226f
8 changed files with 109 additions and 43 deletions

View File

@@ -23,6 +23,21 @@ var ordersUpdateExcludeColumns = []Column{
table.Orders.UserID,
}
func (m *Orders) Update(ctx context.Context) error {
m.UpdatedAt = time.Now()
stmt := table.Orders.UPDATE(table.Orders.MutableColumns.Except(table.Orders.OrderNo, table.Orders.Price, table.Orders.Discount, table.Orders.SubOrderNo, table.Orders.PostID, table.Orders.UserID)).SET(m).WHERE(table.Orders.ID.EQ(Int(m.ID))).RETURNING(table.Orders.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 Orders item: %v", err)
return err
}
m.log().WithField("func", "Update").Infof("Orders item updated successfully")
return nil
}
// BuildConditionWithKey builds the WHERE clause for order queries
func (m *Orders) BuildConditionWithKey(orderNumber *string, userID *int64) BoolExpression {
tbl := table.Orders