@@ -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,20 @@ 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 " + tableName + " ({{.LQ}}%s{{.RQ}}) %%sVALUES (%s)%%s" , 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 " + tableName + " %sDEFAULT VALUES%s"
81
98
{ {else -} }
82
- cache.query = "INSERT INTO { { $ schemaTable } } () VALUES ()%s%s"
99
+ cache.query = "INSERT INTO " + tableName + " () 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 " + tableName + " WHERE %s", strings.Join(returnColumns, "{ {.RQ} },{ {.LQ} }"), strmangle.WhereClause("{ {.LQ} }", "{ {.RQ} }", { {if .Dialect.UseIndexPlaceholders} }1{ {else } }0{ {end} }, { {$alias .DownSingular} }PrimaryKeyColumns))
91
108
{ {else -} }
92
109
{ {if .Dialect.UseOutputClause -} }
93
110
queryOutput = fmt.Sprintf("OUTPUT INSERTED.{ {.LQ} }%s{ {.RQ} } ", strings.Join(returnColumns, "{ {.RQ} },INSERTED.{ {.LQ} }"))
@@ -132,7 +149,7 @@ func (o *{{$alias.UpSingular}}) Insert({{if .NoContext}}exec boil.Executor{{else
132
149
{ {end -} }
133
150
{ {- end} }
134
151
if err != nil {
135
- return errors.Wrap(err, " {{.PkgName}}: unable to insert into {{.Table.Name}} " )
152
+ return errors.Wrap(err, " {{.PkgName}}: unable to insert into " + tableName )
136
153
}
137
154
138
155
{ {if $canLastInsertID -} }
@@ -201,7 +218,7 @@ func (o *{{$alias.UpSingular}}) Insert({{if .NoContext}}exec boil.Executor{{else
201
218
}
202
219
203
220
if err != nil {
204
- return errors.Wrap(err, " {{.PkgName}}: unable to insert into {{.Table.Name}} " )
221
+ return errors.Wrap(err, " {{.PkgName}}: unable to insert into " + tableName )
205
222
}
206
223
{ {end} }
207
224
0 commit comments