Skip to content

Commit

Permalink
chore(template): update .template go-zero/model
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Nov 20, 2024
1 parent d940970 commit b1c7318
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions .template/go-zero/model/customized.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func (m *custom{{.upperStartCamelObject}}Model) BulkInsert(ctx context.Context,

func (m *custom{{.upperStartCamelObject}}Model) FindByCondition(ctx context.Context, session sqlx.Session, conds ...condition.Condition) ([]*{{.upperStartCamelObject}}, error) {
sb := sqlbuilder.Select({{.lowerStartCamelObject}}FieldNames...).From(m.table)
condition.ApplySelect(sb, conds...)
statement, args := sb.Build()
builder := condition.Select(*sb, conds...)
statement, args := builder.Build()

var resp []*{{.upperStartCamelObject}}
var err error
Expand All @@ -37,9 +37,9 @@ func (m *custom{{.upperStartCamelObject}}Model) FindByCondition(ctx context.Cont
func (m *custom{{.upperStartCamelObject}}Model) FindOneByCondition(ctx context.Context, session sqlx.Session, conds ...condition.Condition) (*{{.upperStartCamelObject}}, error) {
sb := sqlbuilder.Select({{.lowerStartCamelObject}}FieldNames...).From(m.table)

condition.ApplySelect(sb, conds...)
sb.Limit(1)
statement, args := sb.Build()
builder := condition.Select(*sb, conds...)
builder.Limit(1)
statement, args := builder.Build()

var resp {{.upperStartCamelObject}}
var err error
Expand All @@ -59,20 +59,20 @@ func (m *custom{{.upperStartCamelObject}}Model) PageByCondition(ctx context.Cont
sb := sqlbuilder.Select({{.lowerStartCamelObject}}FieldNames...).From(m.table)
countsb := sqlbuilder.Select("count(*)").From(m.table)

condition.ApplySelect(sb, conds...)
builder := condition.Select(*sb, conds...)

var countConds []condition.Condition
for _, cond := range conds {
if cond.Operator != condition.Limit && cond.Operator != condition.Offset {
countConds = append(countConds, cond)
}
}
condition.ApplySelect(countsb, countConds...)
countBuilder := condition.Select(*countsb, countConds...)

var resp []*{{.upperStartCamelObject}}
var err error

statement, args := sb.Build()
statement, args := builder.Build()

if session != nil {
err = session.QueryRowsCtx(ctx, &resp, statement, args...)
Expand All @@ -84,7 +84,7 @@ func (m *custom{{.upperStartCamelObject}}Model) PageByCondition(ctx context.Cont
}

var total int64
statement, args = countsb.Build()
statement, args = countBuilder.Build()
if session != nil {
err = session.QueryRowCtx(ctx, &total, statement, args...)
} else {
Expand All @@ -103,15 +103,15 @@ func (m *custom{{.upperStartCamelObject}}Model) UpdateFieldsByCondition(ctx cont
}

sb := sqlbuilder.Update(m.table)
condition.ApplyUpdate(sb, conds...)
builder := condition.Update(*sb, conds...)

var assigns []string
for key, value := range field {
assigns = append(assigns, sb.Assign(key, value))
}
sb.Set(assigns...)
builder.Set(assigns...)

statement, args := sb.Build()
statement, args := builder.Build()

var err error
if session != nil {
Expand All @@ -130,8 +130,8 @@ func (m *custom{{.upperStartCamelObject}}Model) DeleteByCondition(ctx context.Co
return nil
}
sb := sqlbuilder.DeleteFrom(m.table)
condition.ApplyDelete(sb, conds...)
statement, args := sb.Build()
builder := condition.Delete(*sb, conds...)
statement, args := builder.Build()

var err error
if session != nil {
Expand Down
16 changes: 8 additions & 8 deletions .template/go-zero/model/delete.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, session sqlx.Session, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
sb := sqlbuilder.DeleteFrom(m.table)
sb.Where(sb.EQ("{{.originalPrimaryKey}}", {{.lowerStartCamelPrimaryKey}}))
statement, args := sb.Build()
var err error
if session != nil {
_, err = session.ExecCtx(ctx, statement, args...)
}else{
_, err = m.conn.ExecCtx(ctx, statement, args...)
}
sb.Where(sb.EQ("{{.originalPrimaryKey}}", {{.lowerStartCamelPrimaryKey}}))
statement, args := sb.Build()
var err error
if session != nil {
_, err = session.ExecCtx(ctx, statement, args...)
} else {
_, err = m.conn.ExecCtx(ctx, statement, args...)
}
return err
}

Expand Down

0 comments on commit b1c7318

Please sign in to comment.