-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_data_repository.go
50 lines (45 loc) · 1.26 KB
/
health_data_repository.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
package main
import (
r "github.com/dancannon/gorethink"
"strings"
)
var healthDataTable = r.Table("healthData")
func saveHealthData(healthData *HealthData) (string, error) {
Info.Println("Writing healthData to DB")
resp, err := healthDataTable.Insert(&healthData).RunWrite(Rethink)
if err != nil {
return "", err
}
Info.Printf("%d row inserted with id %v\n", resp.Inserted, resp.GeneratedKeys)
return strings.Join(resp.GeneratedKeys, ""), nil
}
func findHealthData() ([]HealthData, error) {
Info.Printf("Searching for healthData")
resp, err := healthDataTable.Run(Rethink)
if err != nil {
return nil, err
}
defer resp.Close()
if resp.IsNil() {
return nil, NotFoundError{}
}
var healthData []HealthData
err = resp.All(&healthData)
if err != nil {
return nil, err
}
Info.Printf("Found %d healthData", len(healthData))
return healthData, nil
}
func removeHealthData(id string) error {
Info.Println("Deleting healthData "+ id)
resp, err := healthDataTable.Get(id).Delete().RunWrite(Rethink)
if err != nil {
return err
}
if resp.Deleted == 0 {
return NotFoundError{}
}
Info.Println("Removed healthData "+ id)
return nil
}