This commit is contained in:
aozhiwei 2024-06-13 17:51:05 +08:00
parent 684e548134
commit ee715d672d
2 changed files with 55 additions and 0 deletions

View File

@ -266,6 +266,54 @@ func (this *dbPool) PageQuery(
})
}
func (this *dbPool) StreamPageQuery(
dataSource string,
pageSize int32,
cursor int64,
sql string,
params []string,
filter DbQueryFilter,
orderBy string,
cb SteamPageQueryCb,
fillCb func(*DataSet)) {
if (pageSize <= 0) {
pageSize = 1
}
if (pageSize > 1000) {
pageSize = 1000
}
var pagination StreamPagination
finalySql := sql
if filter != nil {
finalySql += filter.GenSql()
}
if orderBy != "" {
finalySql += " " + orderBy + " "
}
//GetSysLog().Info("finalySql:%s", finalySql)
this.queryOne(
dataSource,
finalySql,
params,
func(err error, rows *DataSet) {
if err != nil {
cb(err, &pagination)
return
}
pagination.PreviousCursor = cursor
for rows.Next() {
if (rows.NumOfReaded() < int64(pageSize)) {
fillCb(rows)
} else if (rows.NumOfReaded() == int64(pageSize)) {
pagination.NextCursor = q5.ToInt64(rows.GetByName("idx"))
} else if (rows.NumOfReaded() > int64(pageSize)) {
pagination.Remaining = 1
}
}
cb(nil, &pagination)
})
}
func (this *dbPool) borrowConn(name string) *dataSource {
tryCount := 0
for tryCount < 5 {

View File

@ -29,12 +29,19 @@ type Pagination struct {
Rows *DataSet
}
type StreamPagination struct {
NextCursor int64
PreviousCursor int64
Remaining int32
}
type HandlerFunc func(*Context)
type GinHandlerFunc func(*gin.Context)
type QueryResultCb func(error, *DataSet)
type QueryOneCb func(error, *DataSet)
type PageQueryCb func(error, *Pagination)
type SteamPageQueryCb func(error, *StreamPagination)
type ExecResultCb func(error, int64, int64)
type middleware struct {