mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Add onclose callback
This commit is contained in:
@@ -7,7 +7,10 @@ import (
|
||||
type Callback func(ctx context.Context, iter interface{}) (err error)
|
||||
type Callbacks []Callback
|
||||
|
||||
type OnDecode Callback
|
||||
type (
|
||||
OnDecode Callback
|
||||
OnClose Callback
|
||||
)
|
||||
|
||||
// Invoke callbacks sequence
|
||||
func (c Callbacks) Invoke(ctx context.Context, iter interface{}) (err error) {
|
||||
|
||||
@@ -130,8 +130,13 @@ func applyCallbacks(q *Query, f interface{}) (ok bool) {
|
||||
switch cb := f.(type) {
|
||||
case OnDecode:
|
||||
q.ondecode = append(q.ondecode, Callback(cb))
|
||||
ok = true
|
||||
case OnClose:
|
||||
q.onclose = append(q.onclose, Callback(cb))
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
ok = true
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ type Query struct {
|
||||
skipper Skipper
|
||||
preloader Preloader
|
||||
ondecode Callbacks
|
||||
onclose Callbacks
|
||||
}
|
||||
|
||||
// And function pushes the elem query to the $and array of the query
|
||||
@@ -81,6 +82,10 @@ func (q *Query) OnDecode() (callbacks Callbacks) {
|
||||
return q.ondecode
|
||||
}
|
||||
|
||||
func (q *Query) OnClose() (callbacks Callbacks) {
|
||||
return q.onclose
|
||||
}
|
||||
|
||||
// Empty checks the query for any content
|
||||
func (q *Query) Empty() (isEmpty bool) {
|
||||
return len(q.m) == 0
|
||||
|
||||
Reference in New Issue
Block a user