ezgen

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLog = New(
	200*time.Millisecond,
	false,
	false,
	logger.Info,
)
View Source
var DefaultModelOpt = []gen.ModelOpt{

	gen.FieldType("version", "optimisticlock.Version"),
	gen.FieldType("is_deleted", "soft_delete.DeletedAt"),
	gen.FieldModify(func(f gen.Field) gen.Field {
		if f.ColumnName == "is_deleted" {

			f.GORMTag.Set("softDelete", "flag")
		}
		return f
	}),
}

Functions

func BuildNullable

func BuildNullable(colGo, columnName string) string

func BuildParamsKey

func BuildParamsKey(colGo, colGoType string, unique bool) string

func BuildScope added in v0.1.5

func BuildScope(colGo, columnName, colGoType string, unique bool) string

func Cond

func Cond(cond bool, query any, args ...any) func(db *gorm.DB) *gorm.DB

func CondGen

func CondGen(cond bool, conds ...gen.Condition) func(db gen.Dao) gen.Dao

func FindAndCountTransaction

func FindAndCountTransaction(db *gorm.DB, result interface{}) (int64, error)

func FindAndCountTransactionGen

func FindAndCountTransactionGen(db gen.DO, result interface{}) (int64, error)

func Generate added in v0.1.1

func Generate(params *GenParams, targetDir, entityName string) (err error)

func GenerateDao added in v0.1.1

func GenerateDao(modelStructNames []string, fileName string) error

func GeneratorForeignKey

func GeneratorForeignKey(g *gen.Generator, db *gorm.DB, tableName string) []gen.ModelOpt

func GetDataMapClickHouse

func GetDataMapClickHouse(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (
	dataType string)) map[string]func(gorm.ColumnType) (dataType string)

func GetDataMapMySQL

func GetDataMapMySQL(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (dataType string)) map[string]func(gorm.ColumnType) (dataType string)

func GetDataMapPostgreSQL added in v0.2.0

func GetDataMapPostgreSQL(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (
	dataType string)) map[string]func(gorm.ColumnType) (dataType string)

func GetDatabaseName

func GetDatabaseName(db *gorm.DB) (string, error)

GetDatabaseName 获取当前连接的数据库名称

func GetRelationship

func GetRelationship(constraintName string) (field.RelationshipType, string, error)

func New

func New(slowThreshold time.Duration, ignoreRecordNotFoundError bool, parameterizedQueries bool, logLevel logger.LogLevel) logger.Interface

New initialize logger

func Nullable

func Nullable(cond bool, query any, f func() any) func(db *gorm.DB) *gorm.DB

func NullableGen

func NullableGen(cond bool, f func() []gen.Condition) func(db gen.Dao) gen.Dao

func Paginate

func Paginate(p Pager) func(db *gorm.DB) *gorm.DB

func PaginateGen

func PaginateGen(p Pager) func(db gen.Dao) gen.Dao

func SnakeToPascalCase

func SnakeToPascalCase(s string) string

func TypeNullable

func TypeNullable(columnType gorm.ColumnType, dataType string) string

func WithDeleted

func WithDeleted(withDeleted bool) func(db *gorm.DB) *gorm.DB

func WithDeletedGen

func WithDeletedGen(withDeleted bool) func(db gen.Dao) gen.Dao

func WithDeletedList

func WithDeletedList(withDeleted []bool) func(db *gorm.DB) *gorm.DB

func WithDeletedListGen

func WithDeletedListGen(withDeleted []bool) func(db gen.Dao) gen.Dao

Types

type DbLog

type DbLog struct {
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	ParameterizedQueries      bool
	LogLevel                  logger.LogLevel
}

func (*DbLog) Error

func (l *DbLog) Error(ctx context.Context, msg string, data ...interface{})

Error print error messages

func (*DbLog) Info

func (l *DbLog) Info(ctx context.Context, msg string, data ...interface{})

Info print info

func (*DbLog) LogMode

func (l *DbLog) LogMode(level logger.LogLevel) logger.Interface

LogMode log mode

func (*DbLog) Trace

func (l *DbLog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (*DbLog) Warn

func (l *DbLog) Warn(ctx context.Context, msg string, data ...interface{})

Warn print warn messages

type ForeignKeyInfo

type ForeignKeyInfo struct {
	ConstraintName   string `gorm:"column:CONSTRAINT_NAME"`
	TableName        string `gorm:"column:TABLE_NAME"`
	ColumnName       string `gorm:"column:COLUMN_NAME"`
	ReferencedTable  string `gorm:"column:REFERENCED_TABLE_NAME"`
	ReferencedColumn string `gorm:"column:REFERENCED_COLUMN_NAME"`
	UpdateRule       string `gorm:"column:UPDATE_RULE"`
	DeleteRule       string `gorm:"column:DELETE_RULE"`
}

ForeignKeyInfo 表示外键约束信息

func GetReferencingForeignKeys

func GetReferencingForeignKeys(db *gorm.DB, tableName string) ([]ForeignKeyInfo, error)

GetReferencingForeignKeys 查询引用特定表的外键约束

type GenParams

type GenParams struct {
	ModelPackage   string   // model package
	DaoName        string   // dao name
	ModelName      string   // model name
	S              string   // the first letter(lower case) of simple Name (receiver)
	PKType         string   // primary key type
	ParamsKey      []string // params key
	ParamsScopes   []string // params scopes
	ImportPkgPaths []string
	PrimaryField   string
	PrimaryGoField string
	Desc           bool   // params key sort
	SortField      string // sort field, default is primary key
}

func BuildParams added in v0.1.1

func BuildParams(table, modelStructName string, columnTypes []gorm.ColumnType,
	dataMap map[string]func(gorm.ColumnType) (dataType string)) (*GenParams, error)

type ModelField

type ModelField struct {
	Name             string
	Type             string
	ColumnName       string
	ColumnComment    string
	MultilineComment bool
	Tag              field.Tag
	GORMTag          field.GormTag
	CustomGenType    string
	Relation         *field.Relation
}

ModelField user input structures

type Pager

type Pager interface {
	// GetPageSize 分页大小, 需要大于 0
	GetPageSize() uint32

	// GetPageIndex 分页页码, 需要大于 0
	GetPageIndex() uint32
}

Pager 表示一个可执行分页的参数请求

type ParserMethod

type ParserMethod struct {
	Receiver   ParserParam
	MethodName string
	Doc        string
	Params     []ParserParam
	Result     []ParserParam
	Body       string
}

ParserMethod Apply to query struct and base struct custom method

type ParserParam

type ParserParam struct {
	PkgPath   string // package's path: internal/model
	Package   string // package's name: model
	Name      string // param's name: user
	Type      string // param's type: User
	IsArray   bool   // is array or not
	IsPointer bool   // is pointer or not
}

ParserParam parameters in method

type QueryStructMeta

type QueryStructMeta struct {
	Generated       bool   // whether to generate db model
	FileName        string // generated file name
	S               string // the first letter(lower case)of simple Name (receiver)
	QueryStructName string // internal query struct name
	ModelStructName string // origin/model struct name
	TableName       string // table name in db server
	TableComment    string // table comment in db server
	StructInfo      ParserParam
	Fields          []*ModelField
	Source          SourceCode
	ImportPkgPaths  []string
	ModelMethods    []*ParserMethod // user custom method bind to db base struct
	// contains filtered or unexported fields
}

QueryStructMeta struct info in generated code

func FindTableMeta

func FindTableMeta(tables []any, tableName string) *QueryStructMeta

func ToQueryStructMeta

func ToQueryStructMeta(v any) *QueryStructMeta

type SourceCode

type SourceCode int

SourceCode source code

type TableFilter

type TableFilter struct {
	SkipTables   []string
	SkipPrefixes []string
	SkipSuffixes []string
}

func (*TableFilter) ShouldSkip

func (f *TableFilter) ShouldSkip(tableName string) bool

type TimeRange added in v0.1.5

type TimeRange struct {
	Start time.Time
	End   time.Time
}

func StartEndStr2TimeRange added in v0.1.5

func StartEndStr2TimeRange(startStr, endStr string) (timeRange TimeRange)

Jump to

Keyboard shortcuts

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