-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
query_write_hooks.go
33 lines (27 loc) · 1.13 KB
/
query_write_hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package rethinkdb
import (
p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2"
)
// Rethinkdb proposal: https://github.com/rethinkdb/rethinkdb/issues/5813
// WriteHookFunc called by rethinkdb when document is changed.
// id, oldVal or newVal can be null (test with Branch).
type WriteHookFunc func(id Term, oldVal Term, newVal Term) Term
// SetWriteHook sets function that will be called each time document in a table is being
// inserted, updated, replaced or deleted.
func (t Term) SetWriteHook(hookFunc WriteHookFunc) Term {
var f interface{} = nil
if hookFunc != nil {
f = funcWrap(hookFunc)
}
return constructMethodTerm(t, "SetWriteHook", p.Term_SET_WRITE_HOOK, []interface{}{f}, map[string]interface{}{})
}
// WriteHookInfo is a return type of GetWriteHook func.
type WriteHookInfo struct {
Function []byte `gorethink:"function,omitempty"`
Query string `gorethink:"query,omitempty"`
}
// GetWriteHook reads write hook associated with table.
// Use WriteHookInfo and ReadOne to get results.
func (t Term) GetWriteHook() Term {
return constructMethodTerm(t, "GetWriteHook", p.Term_GET_WRITE_HOOK, []interface{}{}, map[string]interface{}{})
}