用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
# 名称映射规则 名称映射规则主要负责结构体名称到表名和结构体field到表字段的名称映射。由core.IMapper接口的实现者来管理,xorm内置了三种IMapper实现:core.SnakeMapper , core.SameMapper和core.GonicMapper。 * SnakeMapper 支持struct为驼峰式命名,表结构为下划线命名之间的转换,这个是默认的Maper; * SameMapper 支持结构体名称和对应的表名称以及结构体field名称与对应的表字段名称相同的命名; * GonicMapper 和SnakeMapper很类似,但是对于特定词支持更好,比如ID会翻译成id而不是i_d。 当前SnakeMapper为默认值,如果需要改变时,在engine创建完成后使用 ~~~ engine.SetMapper(core.SameMapper{}) ~~~ 同时需要注意的是: * 如果你使用了别的命名规则映射方案,也可以自己实现一个IMapper。 * 表名称和字段名称的映射规则默认是相同的,当然也可以设置为不同,如: ~~~ engine.SetTableMapper(core.SameMapper{}) engine.SetColumnMapper(core.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, uint64 | | BigInt | | float32 | | Float | | float64 | | Double | | complex64, complex128 | json.Marshal / json.UnMarshal | Varchar(64) | | []uint8 | | Blob | | array, slice, map except []uint8 | json.Marshal / json.UnMarshal | Text | | string | | Varchar(255) | | time.Time | | DateTime | | cascade struct | primary key field value | BigInt | | struct | json.Marshal / json.UnMarshal | Text | | Others | | Text | | bool | 1 or 0 | Bool |