2.2.Prefix mapping, Suffix Mapping and Cache Mapping

Decorated mappers can be created based on existing IMapper classes.

  • core.NewPrefixMapper(SnakeMapper{}, "prefix") can add prefix string when naming based on SnakeMapper or SameMapper, or your custom Mapper.

For example,

tbMapper := core.NewPrefixMapper(core.SnakeMapper{}, "prefix_")
engine.SetTableMapper(tbMapper)

Then struct type User struct will be mapping to table prefix_user but not user.

  • core.NewSuffixMapper(SnakeMapper{}, "suffix") can add suffix string when naming based on SnakeMapper or SameMapper, or your custom Mapper.
  • core.NewCacheMapper(SnakeMapper{}) can add a memory cache to an existing mapper.

Of course, you can implement IMapper to create a custom naming strategy.