-
Notifications
You must be signed in to change notification settings - Fork 6
/
broadcaster.go
68 lines (51 loc) · 2.02 KB
/
broadcaster.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package broadcast
import (
"context"
"github.com/goradd/goradd/pkg/watcher"
)
// Broadcaster is the injected broadcaster that the generated forms use to notify the application
// that the database has changed. The application will start with the given default below, but
// you can change it if needed.
var Broadcaster BroadcasterI
type BroadcasterI interface {
Insert(ctx context.Context, dbId string, table string, pk interface{})
Update(ctx context.Context, dbId string, table string, pk interface{}, fieldnames ...string)
Delete(ctx context.Context, dbId string, table string, pk interface{})
BulkChange(ctx context.Context, dbId string, table string)
}
// DefaultBroadcaster broadcasts database changes to the client using the watcher's pub/sub
// mechanism
type DefaultBroadcaster struct {
}
func (b DefaultBroadcaster) Insert(ctx context.Context, dbId string, table string, pk interface{}) {
watcher.BroadcastInsert(ctx, dbId, table, pk)
}
func (b DefaultBroadcaster) Update(ctx context.Context, dbId string, table string, pk interface{}, fieldnames ...string) {
watcher.BroadcastUpdate(ctx, dbId, table, pk, fieldnames)
}
func (b DefaultBroadcaster) Delete(ctx context.Context, dbId string, table string, pk interface{}) {
watcher.BroadcastDelete(ctx, dbId, table, pk)
}
func (b DefaultBroadcaster) BulkChange(ctx context.Context, dbId string, table string) {
watcher.BroadcastBulkChange(ctx, dbId, table)
}
func Insert(ctx context.Context, dbId string, table string, pk interface{}) {
if Broadcaster != nil {
Broadcaster.Insert(ctx, dbId, table, pk)
}
}
func Update(ctx context.Context, dbId string, table string, pk interface{}, fieldnames ...string) {
if Broadcaster != nil {
Broadcaster.Update(ctx, dbId, table, pk, fieldnames...)
}
}
func Delete(ctx context.Context, dbId string, table string, pk interface{}) {
if Broadcaster != nil {
Broadcaster.Delete(ctx, dbId, table, pk)
}
}
func BulkChange(ctx context.Context, dbId string, table string) {
if Broadcaster != nil {
Broadcaster.BulkChange(ctx, dbId, table)
}
}