Documentation
¶
Index ¶
- Variables
- func BuildNullable(colGo, columnName string) string
- func BuildParamsKey(colGo, colGoType string, unique bool) string
- func BuildScope(colGo, columnName, colGoType string, unique bool) string
- func Cond(cond bool, query any, args ...any) func(db *gorm.DB) *gorm.DB
- func CondGen(cond bool, conds ...gen.Condition) func(db gen.Dao) gen.Dao
- func FindAndCountTransaction(db *gorm.DB, result interface{}) (int64, error)
- func FindAndCountTransactionGen(db gen.DO, result interface{}) (int64, error)
- func Generate(params *GenParams, targetDir, entityName string) (err error)
- func GenerateDao(modelStructNames []string, fileName string) error
- func GeneratorForeignKey(g *gen.Generator, db *gorm.DB, tableName string) []gen.ModelOpt
- func GetDataMapClickHouse(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (dataType string)) map[string]func(gorm.ColumnType) (dataType string)
- func GetDataMapMySQL(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (dataType string)) map[string]func(gorm.ColumnType) (dataType string)
- func GetDataMapPostgreSQL(cfg *gen.Config, customMap map[string]func(gorm.ColumnType) (dataType string)) map[string]func(gorm.ColumnType) (dataType string)
- func GetDatabaseName(db *gorm.DB) (string, error)
- func GetRelationship(constraintName string) (field.RelationshipType, string, error)
- func New(slowThreshold time.Duration, ignoreRecordNotFoundError bool, ...) logger.Interface
- func Nullable(cond bool, query any, f func() any) func(db *gorm.DB) *gorm.DB
- func NullableGen(cond bool, f func() []gen.Condition) func(db gen.Dao) gen.Dao
- func Paginate(p Pager) func(db *gorm.DB) *gorm.DB
- func PaginateGen(p Pager) func(db gen.Dao) gen.Dao
- func SnakeToPascalCase(s string) string
- func TypeNullable(columnType gorm.ColumnType, dataType string) string
- func WithDeleted(withDeleted bool) func(db *gorm.DB) *gorm.DB
- func WithDeletedGen(withDeleted bool) func(db gen.Dao) gen.Dao
- func WithDeletedList(withDeleted []bool) func(db *gorm.DB) *gorm.DB
- func WithDeletedListGen(withDeleted []bool) func(db gen.Dao) gen.Dao
- type DbLog
- func (l *DbLog) Error(ctx context.Context, msg string, data ...interface{})
- func (l *DbLog) Info(ctx context.Context, msg string, data ...interface{})
- func (l *DbLog) LogMode(level logger.LogLevel) logger.Interface
- func (l *DbLog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *DbLog) Warn(ctx context.Context, msg string, data ...interface{})
- type ForeignKeyInfo
- type GenParams
- type ModelField
- type Pager
- type ParserMethod
- type ParserParam
- type QueryStructMeta
- type SourceCode
- type TableFilter
- type TimeRange
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultLog = New( 200*time.Millisecond, false, false, logger.Info, )
Functions ¶
func BuildNullable ¶
func BuildParamsKey ¶
func BuildScope ¶ added in v0.1.5
func FindAndCountTransaction ¶
func GenerateDao ¶ added in v0.1.1
func GeneratorForeignKey ¶
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 ¶
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 SnakeToPascalCase ¶
func TypeNullable ¶
func TypeNullable(columnType gorm.ColumnType, dataType string) string
Types ¶
type DbLog ¶
type DbLog struct {
SlowThreshold time.Duration
IgnoreRecordNotFoundError bool
ParameterizedQueries bool
LogLevel logger.LogLevel
}
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 TableFilter ¶
func (*TableFilter) ShouldSkip ¶
func (f *TableFilter) ShouldSkip(tableName string) bool
Click to show internal directories.
Click to hide internal directories.