update: 支持PGORM的time和timetz类型

This commit is contained in:
zodial
2025-05-07 12:30:33 +08:00
parent 5986b31be0
commit a41bc8b016
3 changed files with 32 additions and 2 deletions

View File

@@ -202,6 +202,20 @@ func (orm *OrmMysqlTableName) Paginate(page int, limit int) (MysqlTableNameList,
return list, total
}
// SimplePaginate 不统计总数的分页
func (orm *OrmMysqlTableName) SimplePaginate(page int, limit int) MysqlTableNameList {
list := make([]*MysqlTableName, 0)
if page == 0 {
page = 1
}
offset := (page - 1) * limit
tx := orm.db.Offset(offset).Limit(limit).Find(&list)
if tx.Error != nil {
logrus.Error(tx.Error)
}
return list
}
// FindInBatches find records in batches
func (orm *OrmMysqlTableName) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB {
return orm.db.FindInBatches(dest, batchSize, fc)

View File

@@ -536,8 +536,10 @@ func PgTypeToGoType(pgType string, columnName string) string {
return "database.Time"
case "json", "jsonb":
return "database.JSON"
case "time", "timetz":
return "database.Time"
case "time":
return "database.PgTime"
case "timetz":
return "database.PgTimeTz"
case "float4":
return "float32"
case "float8", "numeric":

View File

@@ -202,6 +202,20 @@ func (orm *Orm{orm_table_name}) Paginate(page int, limit int) ({orm_table_name}L
return list, total
}
// SimplePaginate 不统计总数的分页
func (orm *Orm{orm_table_name}) SimplePaginate(page int, limit int) {orm_table_name}List {
list := make([]*{orm_table_name}, 0)
if page == 0 {
page = 1
}
offset := (page - 1) * limit
tx := orm.db.Offset(offset).Limit(limit).Find(&list)
if tx.Error != nil {
logrus.Error(tx.Error)
}
return list
}
// FindInBatches find records in batches
func (orm *Orm{orm_table_name}) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB {
return orm.db.FindInBatches(dest, batchSize, fc)