-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
47 lines (36 loc) · 880 Bytes
/
query.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
package main
import (
"google.golang.org/api/iterator"
"log"
"time"
//"encoding/json"
"fmt"
)
func QueryBookings(arguments []string) {
_ = arguments
if client == nil {
fmt.Printf("not connected - use %q\n", "connect")
return
}
collection = "bookings"
from := time.Date(2020, time.September, 20, 0, 0, 0, 0, time.UTC)
to := time.Date(2020, time.December, 21, 23, 0, 0, 0, time.UTC)
query := client.Collection(collection).
Where("from", ">=", from)
iter := query.Documents(ctx)
for {
doc, err := iter.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Fatalf("Failed to iterate: %v", err)
}
//fmt.Printf("where from: %q\n\n", doc.Data())
if doc.Data()["to"].(time.Time).Unix() <= to.Unix() {
fmt.Printf("between yesterday and tomorrow: %q\n\n", doc.Data())
} else {
fmt.Printf("NOT: %q\n\n", doc.Data())
}
}
}