File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import (
1111type QueryBuilder interface {
1212 InsertStatement (stmt InsertStatement ) string
1313
14+ SelectStatement (stmt SelectStatement ) string
15+
1416 BuildColumns (entity Entity , columns []string , excludedColumns []string ) []string
1517}
1618
@@ -41,6 +43,25 @@ func (qb *queryBuilder) InsertStatement(stmt InsertStatement) string {
4143 )
4244}
4345
46+ func (qb * queryBuilder ) SelectStatement (stmt SelectStatement ) string {
47+ columns := qb .BuildColumns (stmt .Entity (), stmt .Columns (), stmt .ExcludeColumns ())
48+ from := stmt .Table ()
49+ if from == "" {
50+ from = TableName (stmt .Entity ())
51+ }
52+ where := stmt .Where ()
53+ if where != "" {
54+ where = fmt .Sprintf (" WHERE %s" , where )
55+ }
56+
57+ return fmt .Sprintf (
58+ `SELECT "%s" FROM "%s"%s` ,
59+ strings .Join (columns , `", "` ),
60+ from ,
61+ where ,
62+ )
63+ }
64+
4465func (qb * queryBuilder ) BuildColumns (entity Entity , columns []string , excludedColumns []string ) []string {
4566 var deltaColumns []string
4667 if len (columns ) > 0 {
Original file line number Diff line number Diff line change @@ -95,7 +95,6 @@ type selectStatement struct {
9595 columns []string
9696 excludedColumns []string
9797 where string
98- whereValues []any
9998}
10099
101100func (s * selectStatement ) From (table string ) SelectStatement {
You can’t perform that action at this time.
0 commit comments