@@ -14,8 +14,9 @@ import (
14
14
15
15
"github.com/Masterminds/sprig/v3"
16
16
"github.com/friendsofgo/errors"
17
- "github.com/volatiletech/sqlboiler/v4/drivers"
18
17
"github.com/volatiletech/strmangle"
18
+
19
+ "github.com/volatiletech/sqlboiler/v4/drivers"
19
20
)
20
21
21
22
// templateData for sqlboiler templates
@@ -58,8 +59,12 @@ type templateData struct {
58
59
RelationTag string
59
60
60
61
// Generate struct tags as camelCase or snake_case
62
+ // Deprecated: use StructTagCases instead.
61
63
StructTagCasing string
62
64
65
+ // Generate struct tags as camelCase or snake_case
66
+ StructTagCases StructTagCases
67
+
63
68
// Contains field names that should have tags values set to '-'
64
69
TagIgnore map [string ]struct {}
65
70
@@ -133,7 +138,9 @@ func (t templateList) Templates() []string {
133
138
return ret
134
139
}
135
140
136
- func loadTemplates (lazyTemplates []lazyTemplate , testTemplates bool , customFuncs template.FuncMap ) (* templateList , error ) {
141
+ func loadTemplates (
142
+ lazyTemplates []lazyTemplate , testTemplates bool , customFuncs template.FuncMap ,
143
+ ) (* templateList , error ) {
137
144
tpl := template .New ("" )
138
145
139
146
for _ , t := range lazyTemplates {
@@ -286,13 +293,14 @@ var templateFunctions = template.FuncMap{
286
293
"ignore" : strmangle .Ignore ,
287
294
288
295
// String Slice ops
289
- "join" : func (sep string , slice []string ) string { return strings .Join (slice , sep ) },
290
- "joinSlices" : strmangle .JoinSlices ,
291
- "stringMap" : strmangle .StringMap ,
292
- "prefixStringSlice" : strmangle .PrefixStringSlice ,
293
- "containsAny" : strmangle .ContainsAny ,
294
- "generateTags" : strmangle .GenerateTags ,
295
- "generateIgnoreTags" : strmangle .GenerateIgnoreTags ,
296
+ "join" : func (sep string , slice []string ) string { return strings .Join (slice , sep ) },
297
+ "joinSlices" : strmangle .JoinSlices ,
298
+ "stringMap" : strmangle .StringMap ,
299
+ "prefixStringSlice" : strmangle .PrefixStringSlice ,
300
+ "containsAny" : strmangle .ContainsAny ,
301
+ "generateTags" : strmangle .GenerateTags ,
302
+ "generateTagWithCase" : generateTagWithCase ,
303
+ "generateIgnoreTags" : strmangle .GenerateIgnoreTags ,
296
304
297
305
// Enum ops
298
306
"parseEnumName" : strmangle .ParseEnumName ,
@@ -333,3 +341,32 @@ var templateFunctions = template.FuncMap{
333
341
"columnDBTypes" : drivers .ColumnDBTypes ,
334
342
"getTable" : drivers .GetTable ,
335
343
}
344
+
345
+ func generateTagWithCase (tagName , tagValue , alias string , c TagCase , nullable bool ) string {
346
+ buf := strmangle .GetBuffer ()
347
+ defer strmangle .PutBuffer (buf )
348
+
349
+ buf .WriteString (tagName )
350
+ buf .WriteString (`:"` )
351
+ switch c {
352
+ case TagCaseSnake :
353
+ // we use snake case by default, so we can simply render the value to the buffer
354
+ buf .WriteString (tagValue )
355
+ case TagCaseTitle :
356
+ buf .WriteString (strmangle .TitleCase (tagValue ))
357
+ case TagCaseCamel :
358
+ buf .WriteString (strmangle .CamelCase (tagValue ))
359
+ case TagCaseAlias :
360
+ buf .WriteString (alias )
361
+ default :
362
+ buf .WriteString (tagValue )
363
+ }
364
+
365
+ if nullable {
366
+ buf .WriteString (",omitempty" )
367
+ }
368
+
369
+ buf .WriteString (`" ` )
370
+
371
+ return buf .String ()
372
+ }
0 commit comments