File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
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+ InsertSelectStatement (stmt InsertSelectStatement ) string
15+
1416 SelectStatement (stmt SelectStatement ) string
1517
1618 BuildColumns (entity Entity , columns []string , excludedColumns []string ) []string
@@ -43,6 +45,22 @@ func (qb *queryBuilder) InsertStatement(stmt InsertStatement) string {
4345 )
4446}
4547
48+ func (qb * queryBuilder ) InsertSelectStatement (stmt InsertSelectStatement ) string {
49+ selectStmt := qb .SelectStatement (stmt .Select ())
50+ columns := qb .BuildColumns (stmt .Entity (), stmt .Columns (), stmt .ExcludedColumns ())
51+ into := stmt .Table ()
52+ if into == "" {
53+ into = TableName (stmt .Entity ())
54+ }
55+
56+ return fmt .Sprintf (
57+ `INSERT INTO "%s" ("%s") %s` ,
58+ into ,
59+ strings .Join (columns , `", "` ),
60+ selectStmt ,
61+ )
62+ }
63+
4664func (qb * queryBuilder ) SelectStatement (stmt SelectStatement ) string {
4765 columns := qb .BuildColumns (stmt .Entity (), stmt .Columns (), stmt .ExcludeColumns ())
4866 from := stmt .Table ()
You can’t perform that action at this time.
0 commit comments