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"
|
||||
@@ -14,13 +12,19 @@ import (
|
||||
// conds
|
||||
func (m *Users) CondNotDeleted() Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(table.Users.DeletedAt.IS_NULL())
|
||||
return cond.AND(tblUsers.DeletedAt.IS_NULL())
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Users) CondDeleted() Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(tblUsers.DeletedAt.IS_NOT_NULL())
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Users) CondID(id int64) Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(table.Users.ID.EQ(Int(id)))
|
||||
return cond.AND(tblUsers.ID.EQ(Int(id)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +37,7 @@ func (m *Users) Create(ctx context.Context) error {
|
||||
m.CreatedAt = time.Now()
|
||||
m.UpdatedAt = time.Now()
|
||||
|
||||
stmt := table.Medias.INSERT(table.Users.MutableColumns).MODEL(m).RETURNING(table.Medias.AllColumns)
|
||||
stmt := tblMedias.INSERT(tblUsers.MutableColumns).MODEL(m).RETURNING(tblMedias.AllColumns)
|
||||
m.log().WithField("func", "Create").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -46,7 +50,7 @@ func (m *Users) Create(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (m *Users) BatchCreate(ctx context.Context, models []*Users) error {
|
||||
stmt := table.Users.INSERT(table.Users.MutableColumns).MODELS(models)
|
||||
stmt := tblUsers.INSERT(tblUsers.MutableColumns).MODELS(models)
|
||||
m.log().WithField("func", "BatchCreate").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
@@ -59,7 +63,7 @@ func (m *Users) BatchCreate(ctx context.Context, models []*Users) error {
|
||||
}
|
||||
|
||||
func (m *Users) Delete(ctx context.Context) error {
|
||||
stmt := table.Users.UPDATE().SET(table.Users.DeletedAt.SET(TimestampT(time.Now()))).WHERE(table.Users.ID.EQ(Int(m.ID)))
|
||||
stmt := tblUsers.UPDATE().SET(tblUsers.DeletedAt.SET(TimestampT(time.Now()))).WHERE(tblUsers.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "SoftDelete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -77,7 +81,7 @@ func (m *Users) BatchDelete(ctx context.Context, ids []int64) error {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := table.Users.UPDATE().SET(table.Users.DeletedAt.SET(TimestampT(time.Now()))).WHERE(table.Users.ID.IN(condIds...))
|
||||
stmt := tblUsers.UPDATE().SET(tblUsers.DeletedAt.SET(TimestampT(time.Now()))).WHERE(tblUsers.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchSoftDelete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -85,12 +89,12 @@ func (m *Users) BatchDelete(ctx context.Context, ids []int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchSoftDelete").Infof("Users items soft deleted successfully")
|
||||
m.log().WithField("func", "BatchSoftDelete").WithField("ids", ids).Infof("Users items soft deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Users) ForceDelete(ctx context.Context) error {
|
||||
stmt := table.Users.DELETE().WHERE(table.Users.ID.EQ(Int(m.ID)))
|
||||
stmt := tblUsers.DELETE().WHERE(tblUsers.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "Delete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
@@ -107,40 +111,38 @@ func (m *Users) BatchForceDelete(ctx context.Context, ids []int64) error {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := table.Users.DELETE().WHERE(table.Users.ID.IN(condIds...))
|
||||
stmt := tblUsers.DELETE().WHERE(tblUsers.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchDelete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log().WithField("func", "BatchDelete").Errorf("error deleting Users items: %v", err)
|
||||
m.log().WithField("func", "BatchForceDelete").Errorf("error deleting Users items: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchDelete").Infof("Users items deleted successfully")
|
||||
m.log().WithField("func", "BatchForceDelete").WithField("ids", ids).Infof("Users items deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (m *Users) Update(ctx context.Context) error {
|
||||
//
|
||||
// m.UpdatedAt = time.Now()
|
||||
//
|
||||
func (m *Users) Update(ctx context.Context) error {
|
||||
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)
|
||||
// m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||
stmt := tblUsers.UPDATE(tblUsersUpdateMutableColumns).SET(m).WHERE(tblUsers.ID.EQ(Int(m.ID))).RETURNING(tblUsers.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
|
||||
// }
|
||||
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
|
||||
// }
|
||||
m.log().WithField("func", "Update").Infof("Users item updated successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByCond
|
||||
func (m *Users) GetByCond(ctx context.Context, conds ...Cond) (*Users, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
stmt := table.Users.SELECT(table.Users.AllColumns).WHERE(cond)
|
||||
stmt := tblUsers.SELECT(tblUsers.AllColumns).WHERE(cond)
|
||||
m.log().WithField("func", "GetByCond").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
@@ -161,7 +163,7 @@ func (m *Users) GetByID(ctx context.Context, id int64, conds ...Cond) (*Users, e
|
||||
func (m *Users) Count(ctx context.Context, conds ...Cond) (int64, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
tbl := table.Users
|
||||
tbl := tblUsers
|
||||
stmt := tbl.SELECT(COUNT(tbl.ID).AS("count")).WHERE(cond)
|
||||
m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user