feat: update func
This commit is contained in:
@@ -82,18 +82,20 @@ func (m *Medias) BatchForceDelete(ctx context.Context, ids []int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Medias) Update(ctx context.Context) error {
|
// func (m *Medias) Update(ctx context.Context) error {
|
||||||
stmt := table.Medias.UPDATE(table.Medias.MutableColumns.Except(mediasUpdateExcludeColumns...)).SET(m).WHERE(table.Medias.ID.EQ(Int(m.ID))).RETURNING(table.Medias.AllColumns)
|
//
|
||||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
|
||||||
|
|
||||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
// stmt := table.Medias.UPDATE(table.Medias.MutableColumns.Except(mediasUpdateExcludeColumns...)).SET(m).WHERE(table.Medias.ID.EQ(Int(m.ID))).RETURNING(table.Medias.AllColumns)
|
||||||
m.log().WithField("func", "Update").Errorf("error updating Medias item: %v", err)
|
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
m.log().WithField("func", "Update").Infof("Medias item updated successfully")
|
// if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||||
return nil
|
// m.log().WithField("func","Update").Errorf("error updating Medias item: %v", err)
|
||||||
}
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// m.log().WithField("func", "Update").Infof("Medias item updated successfully")
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
// GetByCond
|
// GetByCond
|
||||||
func (m *Medias) GetByCond(ctx context.Context, conds ...Cond) (*Medias, error) {
|
func (m *Medias) GetByCond(ctx context.Context, conds ...Cond) (*Medias, error) {
|
||||||
|
|||||||
@@ -148,3 +148,16 @@ func (m *Medias) GetRelations(ctx context.Context, hash string) ([]*Medias, erro
|
|||||||
return &media
|
return &media
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Medias) Update(ctx context.Context) error {
|
||||||
|
stmt := table.Medias.UPDATE(table.Medias.MutableColumns.Except(table.Medias.CreatedAt)).SET(m).WHERE(table.Medias.ID.EQ(Int(m.ID))).RETURNING(table.Medias.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 Medias item: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.log().WithField("func", "Update").Infof("Medias item updated successfully")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -83,20 +83,22 @@ func (m *Orders) BatchForceDelete(ctx context.Context, ids []int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Orders) Update(ctx context.Context) error {
|
// func (m *Orders) Update(ctx context.Context) error {
|
||||||
m.UpdatedAt = time.Now()
|
//
|
||||||
|
// m.UpdatedAt = time.Now()
|
||||||
|
//
|
||||||
|
|
||||||
stmt := table.Orders.UPDATE(table.Orders.MutableColumns.Except(ordersUpdateExcludeColumns...)).SET(m).WHERE(table.Orders.ID.EQ(Int(m.ID))).RETURNING(table.Orders.AllColumns)
|
// stmt := table.Orders.UPDATE(table.Orders.MutableColumns.Except(ordersUpdateExcludeColumns...)).SET(m).WHERE(table.Orders.ID.EQ(Int(m.ID))).RETURNING(table.Orders.AllColumns)
|
||||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||||
|
|
||||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
// if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||||
m.log().WithField("func", "Update").Errorf("error updating Orders item: %v", err)
|
// m.log().WithField("func","Update").Errorf("error updating Orders item: %v", err)
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
m.log().WithField("func", "Update").Infof("Orders item updated successfully")
|
// m.log().WithField("func", "Update").Infof("Orders item updated successfully")
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// GetByCond
|
// GetByCond
|
||||||
func (m *Orders) GetByCond(ctx context.Context, conds ...Cond) (*Orders, error) {
|
func (m *Orders) GetByCond(ctx context.Context, conds ...Cond) (*Orders, error) {
|
||||||
|
|||||||
@@ -23,6 +23,21 @@ var ordersUpdateExcludeColumns = []Column{
|
|||||||
table.Orders.UserID,
|
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
|
// BuildConditionWithKey builds the WHERE clause for order queries
|
||||||
func (m *Orders) BuildConditionWithKey(orderNumber *string, userID *int64) BoolExpression {
|
func (m *Orders) BuildConditionWithKey(orderNumber *string, userID *int64) BoolExpression {
|
||||||
tbl := table.Orders
|
tbl := table.Orders
|
||||||
|
|||||||
@@ -119,20 +119,22 @@ func (m *Posts) BatchForceDelete(ctx context.Context, ids []int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Posts) Update(ctx context.Context) error {
|
// func (m *Posts) Update(ctx context.Context) error {
|
||||||
m.UpdatedAt = time.Now()
|
//
|
||||||
|
// m.UpdatedAt = time.Now()
|
||||||
|
//
|
||||||
|
|
||||||
stmt := table.Posts.UPDATE(table.Posts.MutableColumns.Except(postsUpdateExcludeColumns...)).SET(m).WHERE(table.Posts.ID.EQ(Int(m.ID))).RETURNING(table.Posts.AllColumns)
|
// stmt := table.Posts.UPDATE(table.Posts.MutableColumns.Except(postsUpdateExcludeColumns...)).SET(m).WHERE(table.Posts.ID.EQ(Int(m.ID))).RETURNING(table.Posts.AllColumns)
|
||||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||||
|
|
||||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
// if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||||
m.log().WithField("func", "Update").Errorf("error updating Posts item: %v", err)
|
// m.log().WithField("func","Update").Errorf("error updating Posts item: %v", err)
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
m.log().WithField("func", "Update").Infof("Posts item updated successfully")
|
// m.log().WithField("func", "Update").Infof("Posts item updated successfully")
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// GetByCond
|
// GetByCond
|
||||||
func (m *Posts) GetByCond(ctx context.Context, conds ...Cond) (*Posts, error) {
|
func (m *Posts) GetByCond(ctx context.Context, conds ...Cond) (*Posts, error) {
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ var postsUpdateExcludeColumns = []Column{
|
|||||||
table.Posts.Likes,
|
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 {
|
func (m *Posts) CondStatus(s fields.PostStatus) Cond {
|
||||||
return func(cond BoolExpression) BoolExpression {
|
return func(cond BoolExpression) BoolExpression {
|
||||||
return cond.AND(table.Posts.Status.EQ(Int(int64(s))))
|
return cond.AND(table.Posts.Status.EQ(Int(int64(s))))
|
||||||
|
|||||||
@@ -119,20 +119,22 @@ func (m *Users) BatchForceDelete(ctx context.Context, ids []int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Users) Update(ctx context.Context) error {
|
// func (m *Users) Update(ctx context.Context) error {
|
||||||
m.UpdatedAt = time.Now()
|
//
|
||||||
|
// m.UpdatedAt = time.Now()
|
||||||
|
//
|
||||||
|
|
||||||
stmt := table.Users.UPDATE(table.Users.MutableColumns.Except(usersUpdateExcludeColumns...)).SET(m).WHERE(table.Users.ID.EQ(Int(m.ID))).RETURNING(table.Users.AllColumns)
|
// stmt := table.Users.UPDATE(table.Users.MutableColumns.Except(usersUpdateExcludeColumns...)).SET(m).WHERE(table.Users.ID.EQ(Int(m.ID))).RETURNING(table.Users.AllColumns)
|
||||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||||
|
|
||||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
// if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||||
m.log().WithField("func", "Update").Errorf("error updating Users item: %v", err)
|
// m.log().WithField("func","Update").Errorf("error updating Users item: %v", err)
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
m.log().WithField("func", "Update").Infof("Users item updated successfully")
|
// m.log().WithField("func", "Update").Infof("Users item updated successfully")
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// GetByCond
|
// GetByCond
|
||||||
func (m *Users) GetByCond(ctx context.Context, conds ...Cond) (*Users, error) {
|
func (m *Users) GetByCond(ctx context.Context, conds ...Cond) (*Users, error) {
|
||||||
|
|||||||
@@ -21,6 +21,21 @@ var usersUpdateExcludeColumns = []Column{
|
|||||||
table.Users.DeletedAt,
|
table.Users.DeletedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Users) Update(ctx context.Context) error {
|
||||||
|
m.UpdatedAt = time.Now()
|
||||||
|
|
||||||
|
stmt := table.Users.UPDATE(table.Users.MutableColumns.Except(table.Users.OpenID, table.Users.Balance, table.Users.CreatedAt, table.Users.DeletedAt)).SET(m).WHERE(table.Users.ID.EQ(Int(m.ID))).RETURNING(table.Users.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 Users item: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.log().WithField("func", "Update").Infof("Users item updated successfully")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// BuildConditionWithKey builds the WHERE clause for user queries
|
// BuildConditionWithKey builds the WHERE clause for user queries
|
||||||
func (m *Users) BuildConditionWithKey(key *string) BoolExpression {
|
func (m *Users) BuildConditionWithKey(key *string) BoolExpression {
|
||||||
tbl := table.Users
|
tbl := table.Users
|
||||||
|
|||||||
Reference in New Issue
Block a user