Zorm 1.4.1 released, custom field mapping logic

Zorm is a lightweight ORM for golang that supports Dameng (dm), Kingbase, mysql, postgresql, oracle, mssql, and sqlite databases.

Source address: https://gitee.com/chunanyong/zorm

go get gitee.com/chunanyong/zorm 
  • Based on native SQL statements, it is a streamlining and optimization of springrain .
  • Built-in code generator
  • The code is streamlined, with a total of about 2000 lines, detailed comments, convenient for customization and modification.
  • Support transaction propagation, which is the main reason for the birth of zorm
  • Support mysql, postgresql, oracle, mssql, sqlite, dm (Da Meng), kingbase (Ren Da Jincang)
  • Support database read and write separation
  • The update performance of zorm, gorm, and xorm is equivalent. The read performance of zorm is twice as fast as that of gorm and xorm
  • The test case is the document:  https://gitee.com/chunanyong/readygo/blob/master/test/testzorm/BaseDao_test.go

Production use reference  UserStructService.go

Update: Support custom extension field mapping logic, the code is as follows:


//实现CustomDriverValueConver接口,扩展自定义类型,例如 达梦数据库text类型,映射出来的是dm.DmClob类型,无法使用string类型直接接收
type CustomDMText struct{}
//GetDriverValue 根据数据库列类型和实体类属性类型,返回driver.Value的实例
//如果无法获取到structFieldType,例如Map查询,会传入nil
//如果返回值为nil,接口扩展逻辑无效,使用原生的方式接收数据库字段值
func (dmtext CustomDMText) GetDriverValue(columnType *sql.ColumnType, structFieldType reflect.Type) (driver.Value, error) {
	return &dm.DmClob{}, nil
}
//ConverDriverValue 数据库列类型,实体类属性类型,GetDriverValue返回的driver.Value的临时接收值
//如果无法获取到structFieldType,例如Map查询,会传入nil
//返回符合接收类型值的指针,指针,指针!!!!
func (dmtext CustomDMText) ConverDriverValue(columnType *sql.ColumnType, structFieldType reflect.Type, tempDriverValue driver.Value) (interface{}, error) {
	dmClob, _ := tempDriverValue.(*dm.DmClob)
	dmlen, _ := dmClob.GetLength()
	strInt64 := strconv.FormatInt(dmlen, 10)
	dmlenInt, _ := strconv.Atoi(strInt64)
	str, _ := dmClob.ReadString(1, dmlenInt)
	return &str, nil
}
//CustomDriverValueMap 用于配置driver.Value和对应的处理关系,key是 drier.Value 的字符串,例如 *dm.DmClob
//一般是放到init方法里进行添加
zorm.CustomDriverValueMap["*dm.DmClob"] = CustomDMText{}

 

Guess you like

Origin www.oschina.net/news/127816/zorm-1-4-1-released