XORM Manual

2.1.name mapping rule

use xorm.IMapper interface to implement. There are two IMapper implemented: SnakeMapper and SameMapper. SnakeMapper means struct name is word by word and table name or column name as 下划线. SameMapper means same name between struct and table.

SnakeMapper is the default.

engine.SetMapper(SameMapper{})

And you should notice:

  • If you want to use other mapping rule, implement IMapper
  • Tables's mapping rule could be different from Columns':
engine.SetTableMapper(SameMapper{})
engine.SetColumnMapper(SnakeMapper{})

When a struct auto mapping to a database's table, the below table describes how they change to each other:

go type's kind value method xorm type
implemented Conversion Conversion.ToDB / Conversion.FromDB Text
int, int8, int16, int32, uint, uint8, uint16, uint32 Int
int64, uint64BigInt
float32Float
float64Double
complex64, complex128 json.Marshal / json.UnMarshal Varchar(64)
[]uint8Blob
array, slice, map except []uint8 json.Marshal / json.UnMarshal Text
bool1 or 0Bool
stringVarchar(255)
time.TimeDateTime
cascade structprimary key field valueBigInt
structjson.Marshal / json.UnMarshalText
Others Text