Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Commit 5da6965

Browse files
committed
feat(condition): add transfer
feat(condition): add transfer
1 parent 653620e commit 5da6965

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

condition/transfer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package condition
2+
3+
import (
4+
"strconv"
5+
"strings"
6+
7+
"github.com/huandu/go-sqlbuilder"
8+
)
9+
10+
func SelectByWhereRawSql(sb *sqlbuilder.SelectBuilder, originalField string, args ...any) {
11+
originalFields := strings.Split(originalField, " and ")
12+
for i, v := range originalFields {
13+
field := strings.Split(v, " = ")
14+
unquote, _ := strconv.Unquote(field[0])
15+
sb.Where(sb.EQ(unquote, args[i]))
16+
}
17+
}

condition/transfer_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package condition
2+
3+
import (
4+
"testing"
5+
6+
"github.com/huandu/go-sqlbuilder"
7+
)
8+
9+
func TestSelectByWhereRawSql(t *testing.T) {
10+
type args struct {
11+
sb *sqlbuilder.SelectBuilder
12+
originalField string
13+
args []any
14+
}
15+
tests := []struct {
16+
name string
17+
args args
18+
}{
19+
{
20+
name: "test",
21+
args: args{
22+
sb: sqlbuilder.NewSelectBuilder(),
23+
originalField: "`sys_user_id` = ? and `sys_authority_authority_id` = ?",
24+
args: []any{1, 1},
25+
},
26+
},
27+
}
28+
for _, tt := range tests {
29+
t.Run(tt.name, func(t *testing.T) {
30+
SelectByWhereRawSql(tt.args.sb, tt.args.originalField, tt.args.args...)
31+
32+
sql, arguments := tt.args.sb.Build()
33+
t.Log(sql, arguments)
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)