Documentation
¶
Overview ¶
Package ibmdb 实现了GORM与IBM DB2数据库的集成 TODO 基底是来自mysql实现的,功能未完全实现 提供了数据库连接、SQL生成、数据类型映射、事务管理等功能 主要包含以下功能: 1. 数据库连接配置 2. SQL语句构建 3. 数据类型转换 4. 事务管理 5. 数据库迁移支持
Index ¶
- Constants
- Variables
- func BuildQuerySQL(db *gorm.DB)
- func Create(config *callbacks.Config) func(db *gorm.DB)
- func New(config Config) gorm.Dialector
- func Open(dsn string) gorm.Dialector
- func Query(db *gorm.DB)
- type Config
- type Dialector
- func (dialector Dialector) Apply(config *gorm.Config) error
- func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{})
- func (dialector Dialector) ClauseBuilders() map[string]clause.ClauseBuilder
- func (dialector Dialector) DataTypeOf(field *schema.Field) string
- func (dialector Dialector) DefaultValueOf(field *schema.Field) clause.Expression
- func (dialector Dialector) Explain(sql string, vars ...interface{}) string
- func (dialector Dialector) Initialize(db *gorm.DB) (err error)
- func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator
- func (dialector Dialector) Name() string
- func (dialector Dialector) NowFunc(n int) func() time.Time
- func (dialector Dialector) QuoteTo(writer clause.Writer, str string)
- func (dialector Dialector) RollbackTo(tx *gorm.DB, name string) error
- func (dialector Dialector) SavePoint(tx *gorm.DB, name string) error
- func (dialector Dialector) Translate(err error) error
- type Index
- type Migrator
- func (m Migrator) AddColumn(value interface{}, name string) error
- func (m Migrator) AlterColumn(value interface{}, field string) error
- func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
- func (m Migrator) CurrentDatabase() (name string)
- func (m Migrator) CurrentSchema(stmt *gorm.Statement, table string) (string, string)
- func (m Migrator) DropConstraint(value interface{}, name string) error
- func (m Migrator) DropTable(values ...interface{}) error
- func (m Migrator) FullDataTypeOf(field *schema.Field) clause.Expr
- func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error)
- func (m Migrator) GetTables() (tableList []string, err error)
- func (m Migrator) GetTypeAliases(databaseTypeName string) []string
- func (m Migrator) MigrateColumnUnique(value interface{}, field *schema.Field, columnType gorm.ColumnType) error
- func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error
- func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
- func (m Migrator) TableType(value interface{}) (tableType gorm.TableType, err error)
- func (m Migrator) TiDBVersion() (isTiDB bool, major, minor, patch int, err error)
Constants ¶
View Source
const ( DefaultDriverName = "go_ibm_db" AutoRandomTag = "auto_random()" // Treated as an auto_random field for tidb )
View Source
const ( // ClauseOnConflict for clause.ClauseBuilder ON CONFLICT key ClauseOnConflict = "ON CONFLICT" // ClauseValues for clause.ClauseBuilder VALUES key ClauseValues = "VALUES" // ClauseFor for clause.ClauseBuilder FOR key ClauseFor = "FOR" ClauseLimit = "LIMIT" ClauseReturning = "RETURNING" )
Variables ¶
View Source
var ( // CreateClauses create clauses //CreateClauses = []string{"INSERT", "VALUES", "ON CONFLICT"} CreateClauses = []string{"RETURNING", "INSERT", "VALUES", "ON CONFLICT"} // QueryClauses query clauses QueryClauses = []string{"SELECT", "FROM", "WHERE", "GROUP BY", "ORDER BY", "LIMIT", "FOR"} //QueryClauses = []string{} // UpdateClauses update clauses UpdateClauses = []string{"UPDATE", "SET", "WHERE", "ORDER BY", "LIMIT"} // DeleteClauses delete clauses DeleteClauses = []string{"DELETE", "FROM", "WHERE", "ORDER BY", "LIMIT"} )
Functions ¶
func BuildQuerySQL ¶
BuildQuerySQL 构建查询SQL 1. 添加Schema的查询子句 2. 初始化SQL并构建SELECT子句 3. 处理结构体类型的主键条件 4. 处理Selects和Omits字段 5. 处理Join关系 6. 构建最终的SQL语句
Types ¶
type Config ¶
type Config struct {
DriverName string
ServerVersion string
DSN string
//NConfig *mysql.Config
Conn gorm.ConnPool
SkipInitializeWithVersion bool
DefaultStringSize uint
DefaultDatetimePrecision *int
DisableWithReturning bool
DisableDatetimePrecision bool
DontSupportRenameIndex bool
DontSupportRenameColumn bool
DontSupportNullAsDefaultValue bool
DontSupportRenameColumnUnique bool
// As of MySQL 8.0.19, ALTER TABLE permits more general (and SQL standard) syntax
// for dropping and altering existing constraints of any type.
// see https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
DontSupportDropConstraint bool
}
type Dialector ¶
type Dialector struct {
*Config
}
ibmdb Dialector实现了gorm.Dialector接口
Name() string
Initialize(*DB) error
Migrator(db *DB) Migrator
DataTypeOf(*schema.Field) string
DefaultValueOf(*schema.Field) clause.Expression
BindVarTo(writer clause.Writer, stmt *Statement, v interface{})
QuoteTo(clause.Writer, string)
Explain(sql string, vars ...interface{}) string
func (Dialector) ClauseBuilders ¶
func (dialector Dialector) ClauseBuilders() map[string]clause.ClauseBuilder
ClauseBuilders 返回SQL子句构建器 返回:
- 包含各种SQL子句构建器的map
func (Dialector) DataTypeOf ¶
DataTypeOf 将GORM字段类型映射为DB2数据类型 TODO 未完全实现 参数:
- field: 字段schema信息
返回:
- DB2数据类型字符串
func (Dialector) DefaultValueOf ¶
func (dialector Dialector) DefaultValueOf(field *schema.Field) clause.Expression
DefaultValueOf 处理字段默认值 参数:
- field: 字段schema信息
返回:
- SQL表达式
type Index ¶
type Index struct {
TableName string `gorm:"column:TABLE_NAME"`
ColumnName string `gorm:"column:COLUMN_NAME"`
IndexName string `gorm:"column:INDEX_NAME"`
NonUnique int32 `gorm:"column:NON_UNIQUE"`
}
Index table index info
type Migrator ¶
func (Migrator) AlterColumn ¶
func (Migrator) ColumnTypes ¶
func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
ColumnTypes column types return columnTypes,error
func (Migrator) CurrentDatabase ¶
func (Migrator) CurrentSchema ¶
func (Migrator) DropConstraint ¶
func (Migrator) GetTypeAliases ¶
func (Migrator) MigrateColumnUnique ¶
func (m Migrator) MigrateColumnUnique(value interface{}, field *schema.Field, columnType gorm.ColumnType) error
MigrateColumnUnique migrate column's UNIQUE constraint. In MySQL, ColumnType's Unique is affected by UniqueIndex, so we have to take care of the UniqueIndex.
func (Migrator) RenameColumn ¶
func (Migrator) RenameIndex ¶
Click to show internal directories.
Click to hide internal directories.