mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve hook feature for package gdb
This commit is contained in:
@ -39,7 +39,8 @@ type internalParamHook struct {
|
||||
|
||||
type internalParamHookSelect struct {
|
||||
internalParamHook
|
||||
handler HookFuncSelect
|
||||
handler HookFuncSelect
|
||||
queryType int
|
||||
}
|
||||
|
||||
type internalParamHookInsert struct {
|
||||
@ -62,10 +63,9 @@ type internalParamHookDelete struct {
|
||||
// which is usually not be interesting for upper business hook handler.
|
||||
type HookSelectInput struct {
|
||||
internalParamHookSelect
|
||||
Table string
|
||||
Sql string
|
||||
Args []interface{}
|
||||
IsCountStatement bool // IsCountStatement marks this SELECT statement is COUNT statement.
|
||||
Table string
|
||||
Sql string
|
||||
Args []interface{}
|
||||
}
|
||||
|
||||
// HookInsertInput holds the parameters for insert hook operation.
|
||||
@ -111,6 +111,11 @@ func (h *HookSelectInput) Next(ctx context.Context) (result Result, err error) {
|
||||
return h.model.db.DoSelect(ctx, h.link, h.Sql, h.Args...)
|
||||
}
|
||||
|
||||
// IsCountStatement checks and returns whether current SELECT statement is COUNT statement.
|
||||
func (h *HookSelectInput) IsCountStatement() bool {
|
||||
return h.queryType == queryTypeCount
|
||||
}
|
||||
|
||||
// Next calls the next hook handler.
|
||||
func (h *HookInsertInput) Next(ctx context.Context) (result sql.Result, err error) {
|
||||
if h.handler != nil && !h.handlerCalled {
|
||||
|
||||
@ -539,12 +539,12 @@ func (m *Model) doGetAllBySql(queryType int, sql string, args ...interface{}) (r
|
||||
link: m.getLink(false),
|
||||
model: m,
|
||||
},
|
||||
handler: m.hookHandler.Select,
|
||||
handler: m.hookHandler.Select,
|
||||
queryType: queryType,
|
||||
},
|
||||
Table: m.tables,
|
||||
Sql: sql,
|
||||
Args: m.mergeArguments(args),
|
||||
IsCountStatement: queryType == queryTypeCount,
|
||||
Table: m.tables,
|
||||
Sql: sql,
|
||||
Args: m.mergeArguments(args),
|
||||
}
|
||||
result, err = in.Next(m.GetCtx())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user