This repository was archived by the owner on May 31, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 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 , paramJoinString string ) {
11+ paramJoin := strings .Split (paramJoinString , "," )
12+ originalFields := strings .Split (originalField , " and " )
13+ for i , v := range originalFields {
14+ field := strings .Split (v , " = " )
15+ unquote , _ := strconv .Unquote (field [0 ])
16+ sb .Where (sb .EQ (unquote , paramJoin [i ]))
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package condition
2+
3+ import (
4+ "testing"
5+
6+ "github.com/huandu/go-sqlbuilder"
7+ )
8+
9+ func TestSelectWhere (t * testing.T ) {
10+ type args struct {
11+ sb * sqlbuilder.SelectBuilder
12+ originalField string
13+ paramJoinString string
14+ }
15+ tests := []struct {
16+ name string
17+ args args
18+ }{
19+ {
20+ name : "test1" ,
21+ args : args {
22+ sb : sqlbuilder .NewSelectBuilder (),
23+ originalField : "`sys_user_id` = ? and `sys_authority_authority_id` = ?" ,
24+ paramJoinString : "sysUserId,sysAuthorityAuthorityId" ,
25+ },
26+ },
27+
28+ {
29+ name : "test2" ,
30+ args : args {
31+ sb : sqlbuilder .NewSelectBuilder (),
32+ originalField : "`sys_user_id` = ?" ,
33+ paramJoinString : "sysUserId" ,
34+ },
35+ },
36+ }
37+ for _ , tt := range tests {
38+ t .Run (tt .name , func (t * testing.T ) {
39+ SelectByWhereRawSql (tt .args .sb , tt .args .originalField , tt .args .paramJoinString )
40+
41+ sql , arguments := tt .args .sb .Build ()
42+ t .Log (sql , arguments )
43+ })
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments