1
This commit is contained in:
parent
684e548134
commit
ee715d672d
48
dbpool.go
48
dbpool.go
@ -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 {
|
func (this *dbPool) borrowConn(name string) *dataSource {
|
||||||
tryCount := 0
|
tryCount := 0
|
||||||
for tryCount < 5 {
|
for tryCount < 5 {
|
||||||
|
7
types.go
7
types.go
@ -29,12 +29,19 @@ type Pagination struct {
|
|||||||
Rows *DataSet
|
Rows *DataSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StreamPagination struct {
|
||||||
|
NextCursor int64
|
||||||
|
PreviousCursor int64
|
||||||
|
Remaining int32
|
||||||
|
}
|
||||||
|
|
||||||
type HandlerFunc func(*Context)
|
type HandlerFunc func(*Context)
|
||||||
type GinHandlerFunc func(*gin.Context)
|
type GinHandlerFunc func(*gin.Context)
|
||||||
|
|
||||||
type QueryResultCb func(error, *DataSet)
|
type QueryResultCb func(error, *DataSet)
|
||||||
type QueryOneCb func(error, *DataSet)
|
type QueryOneCb func(error, *DataSet)
|
||||||
type PageQueryCb func(error, *Pagination)
|
type PageQueryCb func(error, *Pagination)
|
||||||
|
type SteamPageQueryCb func(error, *StreamPagination)
|
||||||
type ExecResultCb func(error, int64, int64)
|
type ExecResultCb func(error, int64, int64)
|
||||||
|
|
||||||
type middleware struct {
|
type middleware struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user