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 +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-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 , 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+ }
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 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+ }
You can’t perform that action at this time.
0 commit comments