gen

package module
v0.0.0-...-4162934 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 33 Imported by: 0

README

GORM Gen

Friendly & Safer GORM powered by Code Generation.

Release Go Report Card MIT license OpenIssue ClosedIssue TODOs Go.Dev reference

Overview

  • Idiomatic & Reusable API from Dynamic Raw SQL
  • 100% Type-safe DAO API without interface{}
  • Database To Struct follows GORM conventions
  • GORM under the hood, supports all features, plugins, DBMS that GORM supports

Getting Started

Maintainers

@riverchu @iDer @qqxhb @dino-ma

@jinzhu

Contributing

You can help to deliver a better GORM/Gen, check out things you can do

License

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FieldNew add new field (any type your want)
	FieldNew = func(fieldName, fieldType, fieldTag string) model.CreateFieldOpt {
		return func(*model.Field) *model.Field {
			return &model.Field{
				Name:         fieldName,
				Type:         fieldType,
				OverwriteTag: fieldTag,
			}
		}
	}
	// FieldIgnore ignore some columns by name
	FieldIgnore = func(columnNames ...string) model.FilterFieldOpt {
		return func(m *model.Field) *model.Field {
			for _, name := range columnNames {
				if m.ColumnName == name {
					return nil
				}
			}
			return m
		}
	}
	// FieldIgnoreReg ignore some columns by RegExp
	FieldIgnoreReg = func(columnNameRegs ...string) model.FilterFieldOpt {
		regs := make([]regexp.Regexp, len(columnNameRegs))
		for i, reg := range columnNameRegs {
			regs[i] = *regexp.MustCompile(reg)
		}
		return func(m *model.Field) *model.Field {
			for _, reg := range regs {
				if reg.MatchString(m.ColumnName) {
					return nil
				}
			}
			return m
		}
	}
	// FieldRename specify field name in generated struct
	FieldRename = func(columnName string, newName string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.Name = newName
			}
			return m
		}
	}
	// FieldComment specify field comment in generated struct
	FieldComment = func(columnName string, comment string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.ColumnComment = comment
				m.MultilineComment = strings.Contains(comment, "\n")
			}
			return m
		}
	}
	// FieldType specify field type in generated struct
	FieldType = func(columnName string, newType string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.Type = newType
			}
			return m
		}
	}
	// FieldTypeReg specify field type in generated struct by RegExp
	FieldTypeReg = func(columnNameReg string, newType string) model.ModifyFieldOpt {
		reg := regexp.MustCompile(columnNameReg)
		return func(m *model.Field) *model.Field {
			if reg.MatchString(m.ColumnName) {
				m.Type = newType
			}
			return m
		}
	}
	// FieldGenType specify field gen type in generated dao
	FieldGenType = func(columnName string, newType string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.CustomGenType = newType
			}
			return m
		}
	}
	// FieldGenTypeReg specify field gen type in generated dao  by RegExp
	FieldGenTypeReg = func(columnNameReg string, newType string) model.ModifyFieldOpt {
		reg := regexp.MustCompile(columnNameReg)
		return func(m *model.Field) *model.Field {
			if reg.MatchString(m.ColumnName) {
				m.CustomGenType = newType
			}
			return m
		}
	}
	// FieldTag specify GORM tag and JSON tag
	FieldTag = func(columnName string, gormTag, jsonTag string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.GORMTag, m.JSONTag = gormTag, jsonTag
			}
			return m
		}
	}
	// FieldJSONTag specify JSON tag
	FieldJSONTag = func(columnName string, jsonTag string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.JSONTag = jsonTag
			}
			return m
		}
	}
	// FieldJSONTagWithNS specify JSON tag with name strategy
	FieldJSONTagWithNS = func(schemaName func(columnName string) (tagContent string)) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if schemaName != nil {
				m.JSONTag = schemaName(m.ColumnName)
			}
			return m
		}
	}
	// FieldGORMTag specify GORM tag
	FieldGORMTag = func(columnName string, gormTag string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.GORMTag = gormTag
			}
			return m
		}
	}
	// FieldNewTag add new tag
	FieldNewTag = func(columnName string, newTag string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if m.ColumnName == columnName {
				m.NewTag += " " + newTag
			}
			return m
		}
	}
	// FieldNewTagWithNS add new tag with name strategy
	FieldNewTagWithNS = func(tagName string, schemaName func(columnName string) string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			if schemaName == nil {
				schemaName = func(name string) string { return name }
			}
			m.NewTag = fmt.Sprintf(`%s %s:"%s"`, m.NewTag, tagName, schemaName(m.ColumnName))
			return m
		}
	}
	// FieldTrimPrefix trim column name's prefix
	FieldTrimPrefix = func(prefix string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			m.Name = strings.TrimPrefix(m.Name, prefix)
			return m
		}
	}
	// FieldTrimSuffix trim column name's suffix
	FieldTrimSuffix = func(suffix string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			m.Name = strings.TrimSuffix(m.Name, suffix)
			return m
		}
	}
	// FieldAddPrefix add prefix to struct's memeber name
	FieldAddPrefix = func(prefix string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			m.Name = prefix + m.Name
			return m
		}
	}
	// FieldAddSuffix add suffix to struct's memeber name
	FieldAddSuffix = func(suffix string) model.ModifyFieldOpt {
		return func(m *model.Field) *model.Field {
			m.Name += suffix
			return m
		}
	}
	// FieldRelate relate to table in database
	FieldRelate = func(relationship field.RelationshipType, fieldName string, table *generate.QueryStructMeta, config *field.RelateConfig) model.CreateFieldOpt {
		if config == nil {
			config = &field.RelateConfig{}
		}
		if config.JSONTag == "" {
			config.JSONTag = ns.ColumnName("", fieldName)
		}
		return func(*model.Field) *model.Field {
			return &model.Field{
				Name:         fieldName,
				Type:         config.RelateFieldPrefix(relationship) + table.StructInfo.Type,
				JSONTag:      config.JSONTag,
				GORMTag:      config.GORMTag,
				NewTag:       config.NewTag,
				OverwriteTag: config.OverwriteTag,

				Relation: field.NewRelationWithType(
					relationship, fieldName, table.StructInfo.Package+"."+table.StructInfo.Type,
					table.Relations()...),
			}
		}
	}
	// FieldRelateModel relate to exist table model
	FieldRelateModel = func(relationship field.RelationshipType, fieldName string, relModel interface{}, config *field.RelateConfig) model.CreateFieldOpt {
		st := reflect.TypeOf(relModel)
		if st.Kind() == reflect.Ptr {
			st = st.Elem()
		}
		fieldType := st.String()

		if config == nil {
			config = &field.RelateConfig{}
		}
		if config.JSONTag == "" {
			config.JSONTag = ns.ColumnName("", fieldName)
		}

		return func(*model.Field) *model.Field {
			return &model.Field{
				Name:         fieldName,
				Type:         config.RelateFieldPrefix(relationship) + fieldType,
				JSONTag:      config.JSONTag,
				GORMTag:      config.GORMTag,
				NewTag:       config.NewTag,
				OverwriteTag: config.OverwriteTag,

				Relation: field.NewRelationWithModel(relationship, fieldName, fieldType, relModel),
			}
		}
	}

	// WithMethod add custom method for table model
	WithMethod = func(methods ...interface{}) model.AddMethodOpt {
		return func() []interface{} { return methods }
	}
)
View Source
var (
	// Debug use DB in debug mode
	Debug doOptions = func(db *gorm.DB) *gorm.DB { return db.Debug() }
)
View Source
var (
	DefaultMethodTableWithNamer = (&defaultModel{}).TableName
)
View Source
var (
	// ErrEmptyCondition empty condition
	ErrEmptyCondition = errors.New("empty condition")
)

Functions

func CheckClause

func CheckClause(cond clause.Expression) error

CheckClause check security of Expression

Types

type Columns

type Columns []field.Expr

Columns columns array

func (Columns) Eq

func (cs Columns) Eq(query SubQuery) field.Expr

Eq ...

func (Columns) Gt

func (cs Columns) Gt(query SubQuery) field.Expr

Gt ...

func (Columns) Gte

func (cs Columns) Gte(query SubQuery) field.Expr

Gte ...

func (Columns) In

func (cs Columns) In(queryOrValue Condition) field.Expr

In accept query or value

func (Columns) Lt

func (cs Columns) Lt(query SubQuery) field.Expr

Lt ...

func (Columns) Lte

func (cs Columns) Lte(query SubQuery) field.Expr

Lte ...

func (Columns) Neq

func (cs Columns) Neq(query SubQuery) field.Expr

Neq ...

func (Columns) NotIn

func (cs Columns) NotIn(queryOrValue Condition) field.Expr

NotIn ...

func (Columns) Set

func (cs Columns) Set(query SubQuery) field.AssignExpr

Set assign value by subquery

type Condition

type Condition interface {
	BeCond() interface{}
	CondError() error
}

Condition query condition field.Expr and subquery are expect value

func Cond

func Cond(exprs ...clause.Expression) []Condition

Cond convert expression array to condition array

type Config

type Config struct {
	OutPath      string // query code path
	OutFile      string // query code file name, default: gen.go
	ModelPkgPath string // generated model code's package name
	WithUnitTest bool   // generate unit test for query code

	// generate model global configuration
	FieldNullable     bool // generate pointer when field is nullable
	FieldCoverable    bool // generate pointer when field has default value, to fix problem zero value cannot be assign: https://gorm.io/docs/create.html#Default-Values
	FieldSignable     bool // detect integer field's unsigned type, adjust generated data type
	FieldWithIndexTag bool // generate with gorm index tag
	FieldWithTypeTag  bool // generate with gorm column type tag

	Mode GenerateMode // generate mode
	// contains filtered or unexported fields
}

Config generator's basic configuration

func (*Config) Revise

func (cfg *Config) Revise() (err error)

Revise format path and db

func (*Config) WithDataTypeMap

func (cfg *Config) WithDataTypeMap(newMap map[string]func(detailType string) (dataType string))

WithDataTypeMap specify data type mapping relationship, only work when syncing table from db

func (*Config) WithDbNameOpts

func (cfg *Config) WithDbNameOpts(opts ...model.SchemaNameOpt)

WithDbNameOpts set get database name function

func (*Config) WithFileNameStrategy

func (cfg *Config) WithFileNameStrategy(ns func(tableName string) (fileName string))

WithFileNameStrategy specify file name naming strategy, only work when syncing table from db

func (*Config) WithImportPkgPath

func (cfg *Config) WithImportPkgPath(paths ...string)

WithImportPkgPath specify import package path

func (*Config) WithJSONTagNameStrategy

func (cfg *Config) WithJSONTagNameStrategy(ns func(columnName string) (tagContent string))

WithJSONTagNameStrategy specify json tag naming strategy

func (*Config) WithModelNameStrategy

func (cfg *Config) WithModelNameStrategy(ns func(tableName string) (modelName string))

WithModelNameStrategy specify model struct name naming strategy, only work when syncing table from db

func (*Config) WithNewTagNameStrategy

func (cfg *Config) WithNewTagNameStrategy(ns func(columnName string) (tagContent string))

WithNewTagNameStrategy specify new tag naming strategy

func (*Config) WithOpts

func (cfg *Config) WithOpts(opts ...ModelOpt)

WithOpts set global model options

func (*Config) WithTableNameStrategy

func (cfg *Config) WithTableNameStrategy(ns func(tableName string) (targetTableName string))

WithTableNameStrategy specify table name naming strategy, only work when syncing table from db

type DO

type DO struct {
	*DOConfig
	// contains filtered or unexported fields
}

DO (data object): implement basic query methods the structure embedded with a *gorm.DB, and has a element item "alias" will be used when used as a sub query

func (*DO) Alias

func (d *DO) Alias() string

Alias return alias name

func (DO) As

func (d DO) As(alias string) Dao

As alias cannot be heired, As must used on tail

func (*DO) Assign

func (d *DO) Assign(attrs ...field.AssignExpr) Dao

Assign ...

func (*DO) Attrs

func (d *DO) Attrs(attrs ...field.AssignExpr) Dao

Attrs ...

func (*DO) BeCond

func (d *DO) BeCond() interface{}

BeCond implements Condition

func (*DO) Build

func (d *DO) Build(builder clause.Builder)

Build implement the interface of claues.Expression only call WHERE clause's Build

func (*DO) Clauses

func (d *DO) Clauses(conds ...clause.Expression) Dao

Clauses specify Clauses

func (*DO) Columns

func (*DO) Columns(cols ...field.Expr) Columns

Columns return columns for Subquery

func (*DO) CondError

func (d *DO) CondError() error

CondError implements Condition

func (*DO) Count

func (d *DO) Count() (count int64, err error)

Count ...

func (*DO) Create

func (d *DO) Create(value interface{}) error

Create ...

func (*DO) CreateInBatches

func (d *DO) CreateInBatches(value interface{}, batchSize int) error

CreateInBatches ...

func (*DO) Debug

func (d *DO) Debug() Dao

Debug return a DO with db in debug mode

func (*DO) Delete

func (d *DO) Delete(models ...interface{}) (info ResultInfo, err error)

Delete ...

func (*DO) Distinct

func (d *DO) Distinct(columns ...field.Expr) Dao

Distinct ...

func (*DO) Find

func (d *DO) Find() (results interface{}, err error)

Find ...

func (*DO) FindInBatches

func (d *DO) FindInBatches(dest interface{}, batchSize int, fc func(tx Dao, batch int) error) error

FindInBatches ...

func (*DO) First

func (d *DO) First() (result interface{}, err error)

First ...

func (*DO) FirstOrCreate

func (d *DO) FirstOrCreate() (result interface{}, err error)

FirstOrCreate ...

func (*DO) FirstOrInit

func (d *DO) FirstOrInit() (result interface{}, err error)

FirstOrInit ...

func (*DO) Group

func (d *DO) Group(columns ...field.Expr) Dao

Group ...

func (*DO) Having

func (d *DO) Having(conds ...Condition) Dao

Having ...

func (*DO) Join

func (d *DO) Join(table schema.Tabler, conds ...field.Expr) Dao

Join ...

func (*DO) Joins

func (d *DO) Joins(field field.RelationField) Dao

Joins ...

func (*DO) Last

func (d *DO) Last() (result interface{}, err error)

Last ...

func (*DO) LeftJoin

func (d *DO) LeftJoin(table schema.Tabler, conds ...field.Expr) Dao

LeftJoin ...

func (*DO) Limit

func (d *DO) Limit(limit int) Dao

Limit ...

func (*DO) Not

func (d *DO) Not(conds ...Condition) Dao

Not ...

func (*DO) Offset

func (d *DO) Offset(offset int) Dao

Offset ...

func (*DO) Omit

func (d *DO) Omit(columns ...field.Expr) Dao

Omit ...

func (*DO) Or

func (d *DO) Or(conds ...Condition) Dao

Or ...

func (*DO) Order

func (d *DO) Order(columns ...field.Expr) Dao

Order ...

func (*DO) Pluck

func (d *DO) Pluck(column field.Expr, dest interface{}) error

Pluck ...

func (*DO) Preload

func (d *DO) Preload(field field.RelationField) Dao

Preload ...

func (*DO) Quote

func (d *DO) Quote(raw string) string

Quote return qutoed data

func (*DO) ReplaceConnPool

func (d *DO) ReplaceConnPool(pool gorm.ConnPool)

ReplaceConnPool replace db connection pool

func (*DO) ReplaceDB

func (d *DO) ReplaceDB(db *gorm.DB)

ReplaceDB replace db connection

func (DO) Returning

func (d DO) Returning(value interface{}, columns ...string) Dao

Returning backfill data

func (*DO) RightJoin

func (d *DO) RightJoin(table schema.Tabler, conds ...field.Expr) Dao

RightJoin ...

func (*DO) Row

func (d *DO) Row() *sql.Row

Row ...

func (*DO) Rows

func (d *DO) Rows() (*sql.Rows, error)

Rows ...

func (*DO) Save

func (d *DO) Save(value interface{}) error

Save ...

func (*DO) Scan

func (d *DO) Scan(dest interface{}) error

Scan ...

func (*DO) ScanRows

func (d *DO) ScanRows(rows *sql.Rows, dest interface{}) error

ScanRows ...

func (*DO) Scopes

func (d *DO) Scopes(funcs ...func(Dao) Dao) Dao

Scopes ...

func (*DO) Select

func (d *DO) Select(columns ...field.Expr) Dao

Select ...

func (*DO) Session

func (d *DO) Session(config *gorm.Session) Dao

Session replace db with new session

func (DO) TableName

func (d DO) TableName() string

TableName return table name

func (*DO) Take

func (d *DO) Take() (result interface{}, err error)

Take ...

func (*DO) UnderlyingDB

func (d *DO) UnderlyingDB() *gorm.DB

UnderlyingDB return the underlying database connection

func (*DO) Unscoped

func (d *DO) Unscoped() Dao

Unscoped ...

func (*DO) Update

func (d *DO) Update(column field.Expr, value interface{}) (info ResultInfo, err error)

Update ...

func (*DO) UpdateColumn

func (d *DO) UpdateColumn(column field.Expr, value interface{}) (info ResultInfo, err error)

UpdateColumn ...

func (*DO) UpdateColumnSimple

func (d *DO) UpdateColumnSimple(columns ...field.AssignExpr) (info ResultInfo, err error)

UpdateColumnSimple ...

func (*DO) UpdateColumns

func (d *DO) UpdateColumns(value interface{}) (info ResultInfo, err error)

UpdateColumns ...

func (*DO) UpdateFrom

func (d *DO) UpdateFrom(q SubQuery) Dao

UpdateFrom specify update sub query

func (*DO) UpdateSimple

func (d *DO) UpdateSimple(columns ...field.AssignExpr) (info ResultInfo, err error)

UpdateSimple ...

func (*DO) Updates

func (d *DO) Updates(value interface{}) (info ResultInfo, err error)

Updates ...

func (*DO) UseDB

func (d *DO) UseDB(db *gorm.DB, opts ...DOOption)

UseDB specify a db connection(*gorm.DB)

func (*DO) UseModel

func (d *DO) UseModel(model interface{})

UseModel specify a data model structure as a source for table name

func (*DO) UseTable

func (d *DO) UseTable(tableName string)

UseTable specify table name

func (*DO) Where

func (d *DO) Where(conds ...Condition) Dao

Where ...

func (*DO) WithContext

func (d *DO) WithContext(ctx context.Context) Dao

WithContext return a DO with db with context

func (DO) WithResult

func (d DO) WithResult(fc func(tx Dao)) ResultInfo

WithResult ...

type DOConfig

type DOConfig struct {
}

func (*DOConfig) AfterInitialize

func (c *DOConfig) AfterInitialize(db *DO) error

AfterInitialize initialize plugins after db connected

func (*DOConfig) Apply

func (c *DOConfig) Apply(config *DOConfig) error

Apply update config to new config

type DOOption

type DOOption interface {
	Apply(*DOConfig) error
	AfterInitialize(*DO) error
}

DOOption gorm option interface

type Dao

type Dao interface {
	SubQuery
	schema.Tabler
	As(alias string) Dao

	Not(conds ...Condition) Dao
	Or(conds ...Condition) Dao

	Select(columns ...field.Expr) Dao
	Where(conds ...Condition) Dao
	Order(columns ...field.Expr) Dao
	Distinct(columns ...field.Expr) Dao
	Omit(columns ...field.Expr) Dao
	Join(table schema.Tabler, conds ...field.Expr) Dao
	LeftJoin(table schema.Tabler, conds ...field.Expr) Dao
	RightJoin(table schema.Tabler, conds ...field.Expr) Dao
	Group(columns ...field.Expr) Dao
	Having(conds ...Condition) Dao
	Limit(limit int) Dao
	Offset(offset int) Dao
	Scopes(funcs ...func(Dao) Dao) Dao
	Unscoped() Dao
	Attrs(attrs ...field.AssignExpr) Dao
	Assign(attrs ...field.AssignExpr) Dao
	Joins(field field.RelationField) Dao
	Preload(field field.RelationField) Dao
	Clauses(conds ...clause.Expression) Dao

	Create(value interface{}) error
	CreateInBatches(value interface{}, batchSize int) error
	Save(value interface{}) error
	First() (result interface{}, err error)
	Take() (result interface{}, err error)
	Last() (result interface{}, err error)
	Find() (results interface{}, err error)
	FindInBatches(dest interface{}, batchSize int, fc func(tx Dao, batch int) error) error
	FirstOrInit() (result interface{}, err error)
	FirstOrCreate() (result interface{}, err error)
	Update(column field.Expr, value interface{}) (info ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info ResultInfo, err error)
	Updates(values interface{}) (info ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info ResultInfo, err error)
	UpdateColumns(values interface{}) (info ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info ResultInfo, err error)
	Delete(...interface{}) (info ResultInfo, err error)
	Count() (int64, error)
	Row() *sql.Row
	Rows() (*sql.Rows, error)
	Scan(dest interface{}) error
	Pluck(column field.Expr, dest interface{}) error
	ScanRows(rows *sql.Rows, dest interface{}) error
}

Dao CRUD methods

func Table

func Table(subQueries ...SubQuery) Dao

Table return a new table produced by subquery, the return value has to be used as root node

Table(u.Select(u.ID, u.Name).Where(u.Age.Gt(18))).Select()

the above usage is equivalent to SQL statement:

SELECT * FROM (SELECT `id`, `name` FROM `users_info` WHERE `age` > ?)"

type GenerateMode

type GenerateMode uint

GenerateMode generate mode

const (
	// WithDefaultQuery create default query in generated code
	WithDefaultQuery GenerateMode = 1 << iota

	// WithoutContext generate code without context constrain
	WithoutContext

	// WithQueryInterface generate code with exported interface object
	WithQueryInterface
)

type Generator

type Generator struct {
	Config

	Data map[string]*genInfo //gen query data
	// contains filtered or unexported fields
}

Generator code generator

func NewGenerator

func NewGenerator(cfg Config) *Generator

NewGenerator create a new generator

func (*Generator) ApplyBasic

func (g *Generator) ApplyBasic(models ...interface{})

ApplyBasic specify models which will implement basic method

func (*Generator) ApplyInterface

func (g *Generator) ApplyInterface(fc interface{}, models ...interface{})

ApplyInterface specifies method interfaces on structures, implment codes will be generated after calling g.Execute() eg: g.ApplyInterface(func(model.Method){}, model.User{}, model.Company{})

func (*Generator) Execute

func (g *Generator) Execute()

Execute generate code to output path

func (*Generator) GenerateAllTable

func (g *Generator) GenerateAllTable(opts ...ModelOpt) (tableModels []interface{})

GenerateAllTable generate all tables in db

func (*Generator) GenerateModel

func (g *Generator) GenerateModel(tableName string, opts ...ModelOpt) *generate.QueryStructMeta

GenerateModel catch table info from db, return a BaseStruct

func (*Generator) GenerateModelAs

func (g *Generator) GenerateModelAs(tableName string, modelName string, opts ...ModelOpt) *generate.QueryStructMeta

GenerateModelAs catch table info from db, return a BaseStruct

func (*Generator) GenerateModelFrom

func (g *Generator) GenerateModelFrom(obj helper.Object) *generate.QueryStructMeta

GenerateModelFrom generate model from object

func (*Generator) UseDB

func (g *Generator) UseDB(db *gorm.DB)

UseDB set db connection

type M

type M map[string]interface{}

M map[string]interface{}

type ModelOpt

type ModelOpt = model.Option

ModelOpt field option

type ResultInfo

type ResultInfo struct {
	RowsAffected int64
	Error        error
}

ResultInfo query/execute info

type RowsAffected

type RowsAffected int64

RowsAffected execute affected raws

type SubQuery

type SubQuery interface {
	Condition
	// contains filtered or unexported methods
}

SubQuery sub query interface

type T

type T interface{}

T generic type

Directories

Path Synopsis
biz
dal
Package field implement all type field and method
Package field implement all type field and method
internal
utils/pools
Package pools : goroutine pools
Package pools : goroutine pools
tools

Jump to

Keyboard shortcuts

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