@@ -31,11 +31,28 @@ func (o *{{$alias.UpSingular}}) InsertGP({{if not .NoContext}}ctx context.Contex
31
31
32
32
{ {end -} }
33
33
34
+
35
+ // SetCustomTableName sets the custom table name for insertion
36
+ func (o *{ {$alias .UpSingular} }) SetCustomTableName(tableName string) {
37
+ o.customTableName = tableName
38
+ }
39
+
40
+ func (o *{ {$alias .UpSingular} }) getTableName() string {
41
+ if len(o.customTableName) > 0 {
42
+ return o.customTableName
43
+ }
44
+
45
+ return { {$alias .UpSingular} }TableName
46
+ }
47
+
48
+
34
49
// Insert a single record using an executor.
35
50
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
36
51
func (o *{ {$alias .UpSingular} }) Insert({ {if .NoContext} }exec boil.Executor{ {else } }ctx context.Context, exec boil.ContextExecutor{ {end} }, columns boil.Columns) error {
52
+ var tableName = o.getTableName()
53
+
37
54
if o == nil {
38
- return errors.New(" {{.PkgName}}: no {{.Table.Name}} provided for insertion" )
55
+ return errors.New(" {{.PkgName}}: no " + tableName + " provided for insertion" )
39
56
}
40
57
41
58
var err error
@@ -74,20 +91,21 @@ func (o *{{$alias.UpSingular}}) Insert({{if .NoContext}}exec boil.Executor{{else
74
91
return err
75
92
}
76
93
if len(wl) != 0 {
77
- cache.query = fmt.Sprintf(" INSERT INTO {{$schemaTable}} ({{.LQ}}%s{{.RQ}}) %%sVALUES (%s)%%s" , strings.Join(wl, " {{.RQ}},{{.LQ}}" ), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
94
+ cache.query = fmt.Sprintf(" INSERT INTO {{.LQ}}%s{{.RQ}} ({{.LQ}}%s{{.RQ}}) %%sVALUES (%s)%%s" , tableName , strings.Join(wl, " {{.RQ}},{{.LQ}}" ), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
78
95
} else {
79
96
{{if .Dialect.UseDefaultKeyword -} }
80
- cache.query = "INSERT INTO { {$ schemaTable } } %sDEFAULT VALUES%s"
97
+ cache.query = "INSERT INTO { {.LQ } }" + tableName + " { {.RQ } } %sDEFAULT VALUES%s"
81
98
{ {else -} }
82
- cache.query = "INSERT INTO { {$ schemaTable } } () VALUES ()%s%s"
99
+ cache.query = "INSERT INTO { {.LQ } }" + tableName + " { {.RQ } } () VALUES ()%s%s"
83
100
{ {end -} }
84
101
}
85
102
86
103
var queryOutput, queryReturning string
87
104
88
105
if len(cache.retMapping) != 0 {
89
106
{{if .Dialect.UseLastInsertID -} }
90
- cache.retQuery = fmt.Sprintf("SELECT { {.LQ} }%s{ {.RQ} } FROM { {$schemaTable } } WHERE %s", strings.Join(returnColumns, "{ {.RQ} },{ {.LQ} }"), strmangle.WhereClause("{ {.LQ} }", "{ {.RQ} }", { {if .Dialect.UseIndexPlaceholders} }1{ {else } }0{ {end} }, { {$alias .DownSingular} }PrimaryKeyColumns))
107
+ cache.retQuery = fmt.Sprintf("SELECT { {.LQ} }%s{ {.RQ} } FROM { {.LQ} }%s{ {.RQ} } WHERE %s", strings.Join(returnColumns, "{ {.RQ} },{ {.LQ} }"), tableName,
108
+ strmangle.WhereClause("{ {.LQ} }", "{ {.RQ} }", { {if .Dialect.UseIndexPlaceholders} }1{ {else } }0{ {end} }, { {$alias .DownSingular} }PrimaryKeyColumns))
91
109
{ {else -} }
92
110
{ {if .Dialect.UseOutputClause -} }
93
111
queryOutput = fmt.Sprintf("OUTPUT INSERTED.{ {.LQ} }%s{ {.RQ} } ", strings.Join(returnColumns, "{ {.RQ} },INSERTED.{ {.LQ} }"))
@@ -132,7 +150,7 @@ func (o *{{$alias.UpSingular}}) Insert({{if .NoContext}}exec boil.Executor{{else
132
150
{ {end -} }
133
151
{ {- end} }
134
152
if err != nil {
135
- return errors.Wrap(err, " {{.PkgName}}: unable to insert into {{.Table.Name}} " )
153
+ return errors.Wrap(err, " {{.PkgName}}: unable to insert into " + tableName )
136
154
}
137
155
138
156
{ {if $canLastInsertID -} }
@@ -201,7 +219,7 @@ func (o *{{$alias.UpSingular}}) Insert({{if .NoContext}}exec boil.Executor{{else
201
219
}
202
220
203
221
if err != nil {
204
- return errors.Wrap(err, " {{.PkgName}}: unable to insert into {{.Table.Name}} " )
222
+ return errors.Wrap(err, " {{.PkgName}}: unable to insert into " + tableName )
205
223
}
206
224
{ {end} }
207
225
0 commit comments