Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.

Latest commit

 

History

History
19 lines (12 loc) · 783 Bytes

2.prefix.md

File metadata and controls

19 lines (12 loc) · 783 Bytes

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.