@@ -12,11 +12,12 @@ import (
1212// Column table column's info
1313type Column struct {
1414 gorm.ColumnType
15- TableName string `gorm:"column:TABLE_NAME"`
16- Indexes []* Index `gorm:"-"`
17- UseScanType bool `gorm:"-"`
18- dataTypeMap map [string ]func (columnType gorm.ColumnType ) (dataType string ) `gorm:"-"`
19- jsonTagNS func (columnName string ) string `gorm:"-"`
15+ TableName string `gorm:"column:TABLE_NAME"`
16+ Indexes []* Index `gorm:"-"`
17+ UseScanType bool `gorm:"-"`
18+ dataTypeMap map [string ]func (columnType gorm.ColumnType ) (dataType string ) `gorm:"-"`
19+ jsonTagNS func (columnName string ) string `gorm:"-"`
20+ nullableTypeFormater func (columnType string ) string `gorm:"-"`
2021}
2122
2223// SetDataTypeMap set data type map
@@ -43,6 +44,15 @@ func (c *Column) WithNS(jsonTagNS func(columnName string) string) {
4344 }
4445}
4546
47+ // WithNullableFieldTypeNS with nullable type name strategy
48+ // If nil use pointer, the default
49+ func (c * Column ) WithNullableFieldTypeNS (formater func (columnType string ) string ) {
50+ c .nullableTypeFormater = formater
51+ if c .nullableTypeFormater == nil {
52+ c .nullableTypeFormater = func (fType string ) string { return "*" + fType }
53+ }
54+ }
55+
4656// ToField convert to field
4757func (c * Column ) ToField (nullable , coverable , signable bool ) * Field {
4858 fieldType := c .GetDataType ()
@@ -56,7 +66,7 @@ func (c *Column) ToField(nullable, coverable, signable bool) *Field {
5666 fieldType = "*" + fieldType
5767 case nullable && ! strings .HasPrefix (fieldType , "*" ):
5868 if n , ok := c .Nullable (); ok && n {
59- fieldType = "*" + fieldType
69+ fieldType = c . nullableTypeFormater ( fieldType )
6070 }
6171 }
6272
0 commit comments