From a41bc8b016d9052d2af64b4ab210d48d96888153 Mon Sep 17 00:00:00 2001 From: zodial Date: Wed, 7 May 2025 12:30:33 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=94=AF=E6=8C=81PGORM=E7=9A=84time?= =?UTF-8?q?=E5=92=8Ctimetz=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/orm/mysql.go.subtext | 14 ++++++++++++++ console/commands/pgorm/pgsql.go | 6 ++++-- console/commands/pgorm/pgsql.go.subtext | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/console/commands/orm/mysql.go.subtext b/console/commands/orm/mysql.go.subtext index 85e85f8..b19ba10 100644 --- a/console/commands/orm/mysql.go.subtext +++ b/console/commands/orm/mysql.go.subtext @@ -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) diff --git a/console/commands/pgorm/pgsql.go b/console/commands/pgorm/pgsql.go index b971575..762d459 100644 --- a/console/commands/pgorm/pgsql.go +++ b/console/commands/pgorm/pgsql.go @@ -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": diff --git a/console/commands/pgorm/pgsql.go.subtext b/console/commands/pgorm/pgsql.go.subtext index 57272fc..e0832e5 100644 --- a/console/commands/pgorm/pgsql.go.subtext +++ b/console/commands/pgorm/pgsql.go.subtext @@ -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)