gormmom

package module
v0.0.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 21 Imported by: 0

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

gormmom

Empowering Native Language Programming, Simplifying GORM Tag Generation


gormmom is a tool designed to automatically generate GORM tags, aimed at helping developers program in their native language while simplifying the process of defining GORM tags. The tool processes struct fields and automatically generates GORM-compliant tags, ensuring field names follow specific naming conventions.


CHINESE README

中文说明


Features

  • Automatic GORM Tag Generation: Automatically generates GORM tags for struct fields, such as column, index, unique, etc.
  • Native Language Programming Support: Allows developers to define struct fields in their native language (e.g., Chinese), reducing the difficulty of understanding business.

Installation

go get github.com/yyle88/gormmom

Usage Example

Original Code (Native Language Programming)
type Example struct {
    V证号 string `gorm:"primaryKey"`
    V姓名 string `gorm:"index"`
    V年龄 int    `gorm:"unique"`
    V性别 bool   `gorm:"column:sex;uniqueIndex" mom:"naming:S63"`
}
Generated Code (Automatic GORM Tag Generation)
type Example struct {
    V证号 string `gorm:"column:v_c18b_f753;primaryKey" mom:"naming:s63;"`
    V姓名 string `gorm:"column:v_d359_0d54;index:idx_example_v_d359_0d54" mom:"naming:s63;idx:cnm;"`
    V年龄 int    `gorm:"column:v_745e_849f;unique" mom:"naming:s63;"`
    V性别 bool   `gorm:"column:V_2760_2B52;uniqueIndex:udx_example_V_2760_2B52" mom:"naming:S63;udx:cnm;"`
}

Configuration Options

  • naming: Configures the naming convention for database column names.
  • idx: Configures the naming convention for single-column indexes.
  • udx: Configures the naming convention for single-column unique indexes.

Design Ideas

README OLD DOC


License

gormmom is open-source and released under the MIT License. See the LICENSE file for more information.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding with gormmom! 🎉

Give me stars. Thank you!!!

See stars

see stars

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(schemaCache *SchemaCache, options *Options) *Config

func (*Config) GenReplace

func (cfg *Config) GenReplace()

func (*Config) GetNewCode added in v0.0.24

func (cfg *Config) GetNewCode() []byte

type ConfigBatch added in v0.0.24

type ConfigBatch struct {
	// contains filtered or unexported fields
}

func NewConfigBatch added in v0.0.24

func NewConfigBatch(schemaCaches []*SchemaCache, options *Options) *ConfigBatch

func (*ConfigBatch) GenReplaces added in v0.0.24

func (c *ConfigBatch) GenReplaces()

type Options

type Options struct {
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions() *Options

func (*Options) WithColumnNamePatternFieldName added in v0.0.24

func (opt *Options) WithColumnNamePatternFieldName(columnNamePatternFieldName string) *Options

func (*Options) WithColumnNamingStrategies added in v0.0.24

func (opt *Options) WithColumnNamingStrategies(pattern gormmomname.ColumnNamePattern, naming gormmomname.Naming) *Options

func (*Options) WithDefaultColumnNamePattern added in v0.0.24

func (opt *Options) WithDefaultColumnNamePattern(pattern gormmomname.ColumnNamePattern) *Options

func (*Options) WithIndexNamingStrategies added in v0.0.24

func (opt *Options) WithIndexNamingStrategies(pattern gormidxname.IndexNamePattern, naming gormidxname.Naming) *Options

func (*Options) WithNamingTagName added in v0.0.24

func (opt *Options) WithNamingTagName(namingTagName string) *Options

func (*Options) WithRenewIndexName added in v0.0.24

func (opt *Options) WithRenewIndexName(renewIndexName bool) *Options

func (*Options) WithSkipBasicNaming added in v0.0.24

func (opt *Options) WithSkipBasicNaming(skipBasicNaming bool) *Options

type SchemaCache added in v0.0.24

type SchemaCache struct {
	// contains filtered or unexported fields
}

func NewSchemaCache added in v0.0.24

func NewSchemaCache(sourcePath string, structName string, sch *schema.Schema) *SchemaCache

NewSchemaCache 创建参数信息

func NewSchemaCacheV2 added in v0.0.24

func NewSchemaCacheV2[T any](sourcePath string) *SchemaCache

NewSchemaCacheV2 使用泛型创建参数信息。T 只能传类型名称而非带指针的类型名

func NewSchemaCacheV3 added in v0.0.24

func NewSchemaCacheV3(sourcePath string, object interface{}) *SchemaCache

NewSchemaCacheV3 使用对象创建参数信息 object 传对象或者对象指针都行

func NewSchemaCaches added in v0.0.24

func NewSchemaCaches(root string, objects []interface{}) []*SchemaCache

func (*SchemaCache) Validate added in v0.0.24

func (a *SchemaCache) Validate()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL