Skip to content

Commit

Permalink
update the dependency and support op lazy function
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Sep 6, 2024
1 parent 017ba84 commit e6aa4a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/xgfone/go-sqlx

require (
github.com/xgfone/go-defaults v0.19.0
github.com/xgfone/go-op v0.10.0
github.com/xgfone/go-op v0.11.0
)

go 1.21
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/xgfone/go-defaults v0.19.0 h1:sHy3kTdI8Fu8c0EsT0jmzq7mVsm9fmudIaAj4vh8/mc=
github.com/xgfone/go-defaults v0.19.0/go.mod h1:RjyN5TK6hyaROkw2nyfchvCSCOch8rJ/zPO9nO4Y+EQ=
github.com/xgfone/go-op v0.10.0 h1:/fs+UiKwpaweUEioYoxw0+mksvtqCe/IKD+VUIpWBWw=
github.com/xgfone/go-op v0.10.0/go.mod h1:J8xaM7cCXnvDgpU3BjIqNz+1TGAJQPLKHVVeceu+emA=
github.com/xgfone/go-op v0.11.0 h1:6ujAulTlBgyUYy+1G74HRya9JeWcnaT+GXERlSk1X0A=
github.com/xgfone/go-op v0.11.0/go.mod h1:J8xaM7cCXnvDgpU3BjIqNz+1TGAJQPLKHVVeceu+emA=
5 changes: 4 additions & 1 deletion op_updater.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 xgfone
// Copyright 2023~2024 xgfone
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,9 @@ func newUpdaterBatch() OpBuilder {

func newUpdaterSet() OpBuilder {
return OpBuilderFunc(func(ab *ArgsBuilder, op op.Op) string {
if op.Lazy != nil {
op = op.Lazy(op)
}
return fmt.Sprintf("%s=%s", ab.Quote(getOpKey(op)), ab.Add(op.Val))
})
}
Expand Down
13 changes: 12 additions & 1 deletion op_updater_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 xgfone
// Copyright 2023~2024 xgfone
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,3 +68,14 @@ func testsqlargs(t *testing.T, op op.Updater, expectsql string, expectargs ...an
t.Errorf("expect args %v, but got %v", expectargs, args)
}
}

func TestUpdateSet(t *testing.T) {
key := op.KeyReason.WithLazy(op.StrCharsLen(32))

ab := GetArgsBuilderFromPool(MySQL)
BuildOper(ab, key.Set("abcdefghijklmnopqrstuvwxyz0123456789"))
expectargs := []any{"abcdefghijklmnopqrstuvwxyz012345"}
if args := ab.Args(); len(args) != len(expectargs) || !reflect.DeepEqual(args, expectargs) {
t.Errorf("expect args %v, but got %v", expectargs, args)
}
}

0 comments on commit e6aa4a7

Please sign in to comment.