@@ -18,57 +18,57 @@ func main() {
1818 defer db .Close ()
1919
2020 // Use Entry.WithPayload() method to bulk store messages as topic is parsed one time on first request.
21- topic := []byte ("teams.alpha. ch1.r1 " )
21+ topic := []byte ("teams.private.sales. ch1.message " )
2222 entry := & unitdb.Entry {Topic : topic }
2323 for j := 0 ; j < 50 ; j ++ {
24- db .PutEntry (entry .WithPayload ([]byte (fmt .Sprintf ("msg for team alpha channel1 recipient1 #%2d" , j ))))
24+ db .PutEntry (entry .WithPayload ([]byte (fmt .Sprintf ("msg for sales team channel1 #%2d" , j ))))
2525 }
2626
27- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha. ch1.r1 ?last=1h" )).WithLimit (100 )); err == nil {
27+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales. ch1.message ?last=1h" )).WithLimit (100 )); err == nil {
2828 for _ , msg := range msgs {
2929 log .Printf ("%s " , msg )
3030 }
3131 }
3232
3333 // Writing to single topic in a batch
3434 err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
35- topic := []byte ("teams.alpha.ch1.* ?ttl=1h" )
36- b .Put (topic , []byte ("msg for team alpha channel1 all recipients " ))
35+ topic := []byte ("teams.private.sales.*.message ?ttl=1h" )
36+ b .Put (topic , []byte ("msg for sales team all channels " ))
3737 return nil
3838 })
3939 if err != nil {
4040 log .Fatal (err )
4141 return
4242 }
4343
44- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r2 ?last=1h" )).WithLimit (10 )); err == nil {
44+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
4545 for _ , msg := range msgs {
4646 log .Printf ("%s " , msg )
4747 }
4848 }
49- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r3 ?last=1h" )).WithLimit (10 )); err == nil {
49+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch3.message ?last=1h" )).WithLimit (10 )); err == nil {
5050 for _ , msg := range msgs {
5151 log .Printf ("%s " , msg )
5252 }
5353 }
5454
5555 // Writing to multiple topics in a batch
5656 err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
57- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.ch1.r2 " ), []byte ("msg for team alpha channel1 recipient2 " )))
58- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.ch1.r3 " ), []byte ("msg for team alpha channel1 recipient3 " )))
57+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.ch2.message " ), []byte ("msg for sales team channel2 " )))
58+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.ch3.message " ), []byte ("msg for sales team channel3 " )))
5959 return nil
6060 })
6161 if err != nil {
6262 log .Fatal (err )
6363 return
6464 }
6565
66- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r2 ?last=1h" )).WithLimit (10 )); err == nil {
66+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
6767 for _ , msg := range msgs {
6868 log .Printf ("%s " , msg )
6969 }
7070 }
71- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha.ch1.r3 ?last=1h" )).WithLimit (10 )); err == nil {
71+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales.ch3.message ?last=1h" )).WithLimit (10 )); err == nil {
7272 for _ , msg := range msgs {
7373 log .Printf ("%s " , msg )
7474 }
@@ -81,43 +81,43 @@ func main() {
8181 // Writing to single topic in a batch
8282 err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
8383 b .SetOptions (unitdb .WithBatchContract (contract ))
84- topic := []byte ("teams.alpha.ch1.* ?ttl=1h" )
85- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #1 " ))
86- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #2 " ))
87- b .Put (topic , []byte ("msg for team alpha channel1 all recipients #3 " ))
84+ topic := []byte ("teams.private.sales.*.message ?ttl=1h" )
85+ b .Put (topic , []byte ("msg #1 for sales team all channels " ))
86+ b .Put (topic , []byte ("msg #2 for sales team all channels " ))
87+ b .Put (topic , []byte ("msg #3 for sales team all channels " ))
8888 return nil
8989 })
9090
9191 // Writing to multiple topics in a batch
9292 err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
9393 b .SetOptions (unitdb .WithBatchContract (contract ))
94- b .PutEntry (unitdb .NewEntry ([]byte ("teams.*.ch1" ), []byte ("msg for channel1 in any teams" )))
95- b .PutEntry (unitdb .NewEntry ([]byte ("teams.alpha.* " ), []byte ("msg for all channels in team alpha " )))
96- b .PutEntry (unitdb .NewEntry ([]byte ("teams... " ), []byte ("msg for all teams and all channels" )))
97- b .PutEntry (unitdb .NewEntry ([]byte ("..." ), []byte ("msg broadcast to all recipients of all channels in all teams" )))
94+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private. *.ch1.message " ), []byte ("msg for channel1 in any teams" )))
95+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private.sales.*.message " ), []byte ("msg for all channels in sales team " )))
96+ b .PutEntry (unitdb .NewEntry ([]byte ("teams.private... " ), []byte ("msg for all private teams and all channels" )))
97+ b .PutEntry (unitdb .NewEntry ([]byte ("..." ), []byte ("msg broadcast to all channels in all teams" )))
9898 return nil
9999 })
100100 if err != nil {
101101 log .Fatal (err )
102102 return
103103 }
104104
105- // Get message for team alpha channel1
106- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.alpha. ch1?last=1h" )).WithLimit (10 )); err == nil {
105+ // Get message for sales team channel1
106+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.private.sales. ch1.message ?last=1h" )).WithLimit (10 )); err == nil {
107107 for _ , msg := range msgs {
108108 log .Printf ("%s " , msg )
109109 }
110110 }
111111
112- // Get message for team beta channel1
113- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.beta. ch1?last=1h" )).WithLimit (10 )); err == nil {
112+ // Get message for customer support team channel1
113+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.public.customersupport. ch1.message ?last=1h" )).WithLimit (10 )); err == nil {
114114 for _ , msg := range msgs {
115115 log .Printf ("%s " , msg )
116116 }
117117 }
118118
119- // Get message for team beta channel2 recipient11
120- if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.beta. ch2.r1 ?last=1h" )).WithLimit (10 )); err == nil {
119+ // Get message for customer support team channel2
120+ if msgs , err := db .Get (unitdb .NewQuery ([]byte ("teams.public.customersupport. ch2.message ?last=1h" )).WithLimit (10 )); err == nil {
121121 for _ , msg := range msgs {
122122 log .Printf ("%s " , msg )
123123 }
@@ -127,8 +127,8 @@ func main() {
127127 // Note, encryption can also be set on entire database using DB.Open() and set encryption flag in options parameter.
128128 err = db .Batch (func (b * unitdb.Batch , completed <- chan struct {}) error {
129129 b .SetOptions (unitdb .WithBatchEncryption ())
130- topic := []byte ("teams.alpha. ch1.r1 ?ttl=1h" )
131- b .Put (topic , []byte ("msg for team alpha channel1 recipient1 " ))
130+ topic := []byte ("teams.private.sales. ch1.message ?ttl=1h" )
131+ b .Put (topic , []byte ("msg for sales team channel1" ))
132132 return nil
133133 })
134134
0 commit comments