feat: update toolchain
This commit is contained in:
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"quyun/database/table"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/samber/lo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -15,7 +13,7 @@ import (
|
||||
|
||||
func (m *Orders) CondID(id int64) Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(table.Orders.ID.EQ(Int(id)))
|
||||
return cond.AND(tblOrders.ID.EQ(Int(id)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +26,7 @@ func (m *Orders) Create(ctx context.Context) error {
|
||||
m.CreatedAt = time.Now()
|
||||
m.UpdatedAt = time.Now()
|
||||
|
||||
stmt := table.Medias.INSERT(table.Orders.MutableColumns).MODEL(m).RETURNING(table.Medias.AllColumns)
|
||||
stmt := tblMedias.INSERT(tblOrders.MutableColumns).MODEL(m).RETURNING(tblMedias.AllColumns)
|
||||
m.log().WithField("func", "Create").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -41,7 +39,7 @@ func (m *Orders) Create(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (m *Orders) BatchCreate(ctx context.Context, models []*Orders) error {
|
||||
stmt := table.Orders.INSERT(table.Orders.MutableColumns).MODELS(models)
|
||||
stmt := tblOrders.INSERT(tblOrders.MutableColumns).MODELS(models)
|
||||
m.log().WithField("func", "BatchCreate").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
@@ -53,11 +51,11 @@ func (m *Orders) BatchCreate(ctx context.Context, models []*Orders) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Orders) ForceDelete(ctx context.Context) error {
|
||||
stmt := table.Orders.DELETE().WHERE(table.Orders.ID.EQ(Int(m.ID)))
|
||||
func (m *Orders) Delete(ctx context.Context) error {
|
||||
stmt := tblOrders.DELETE().WHERE(tblOrders.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "Delete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func", "Delete").Errorf("error deleting Orders item: %v", err)
|
||||
return err
|
||||
}
|
||||
@@ -66,45 +64,47 @@ func (m *Orders) ForceDelete(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Orders) BatchForceDelete(ctx context.Context, ids []int64) error {
|
||||
// BatchDelete
|
||||
func (m *Orders) BatchDelete(ctx context.Context, ids []int64) error {
|
||||
condIds := lo.Map(ids, func(id int64, _ int) Expression {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := table.Orders.DELETE().WHERE(table.Orders.ID.IN(condIds...))
|
||||
stmt := tblOrders.DELETE().WHERE(tblOrders.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchDelete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func", "BatchDelete").Errorf("error deleting Orders items: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchDelete").Infof("Orders items deleted successfully")
|
||||
m.log().WithField("func", "BatchDelete").WithField("ids", ids).Infof("Orders items deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (m *Orders) Update(ctx context.Context) error {
|
||||
//
|
||||
// m.UpdatedAt = time.Now()
|
||||
//
|
||||
func (m *Orders) Update(ctx context.Context) error {
|
||||
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)
|
||||
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||
stmt := tblOrders.UPDATE(tblOrdersUpdateMutableColumns).
|
||||
SET(m).
|
||||
WHERE(tblOrders.ID.EQ(Int(m.ID))).
|
||||
RETURNING(tblOrders.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
|
||||
// }
|
||||
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
|
||||
// }
|
||||
m.log().WithField("func", "Update").Infof("Orders item updated successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByCond
|
||||
func (m *Orders) GetByCond(ctx context.Context, conds ...Cond) (*Orders, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
stmt := table.Orders.SELECT(table.Orders.AllColumns).WHERE(cond)
|
||||
stmt := tblOrders.SELECT(tblOrders.AllColumns).WHERE(cond)
|
||||
m.log().WithField("func", "GetByCond").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -125,7 +125,7 @@ func (m *Orders) GetByID(ctx context.Context, id int64, conds ...Cond) (*Orders,
|
||||
func (m *Orders) Count(ctx context.Context, conds ...Cond) (int64, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
tbl := table.Orders
|
||||
tbl := tblOrders
|
||||
stmt := tbl.SELECT(COUNT(tbl.ID).AS("count")).WHERE(cond)
|
||||
m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user