-
Notifications
You must be signed in to change notification settings - Fork 31
/
stars.go
65 lines (56 loc) · 1.18 KB
/
stars.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
64
65
/* */
package store
import (
"encoding/json"
"fmt"
"log"
"time"
)
type dataStars struct {
Repo string `json:"repo"`
Source string `json:"source"`
Date string `json:"date"`
Total int `json:"total"`
Data string `json:"data"`
}
func (d dataStars) SaveDataStars() {
d.replaceStars()
//LoadDataStars(d)
}
func (d dataStars) replaceStars() {
sql := fmt.Sprintf("REPLACE INTO %s (repo, source, date, total, data) VALUES (?, ?, ?, ?, ?)",
starsTable)
stmt, err := MyDB.Prepare(sql)
if err != nil {
log.Printf("Error DB 1 replaceStars => %s\n", err)
return
}
defer stmt.Close()
_, err = stmt.Exec(d.Repo, d.Source, d.Date, d.Total, d.Data)
if err != nil {
log.Printf("Error DB 2 replaceStars => %s\n", err)
return
}
}
func (d dataStars) LoadDataStars() {
type point struct {
When string `json:"x"`
Quantity int `json:"y"`
}
var data []point
err := json.Unmarshal([]byte(d.Data), &data)
if err != nil {
log.Printf("ERROR LoadConfig %s\n", err)
}
//u.PrettyPrintStruct(data)
}
func NewDataStars() dataStars {
d := dataStars{
Repo: "",
Source: "",
Date: time.Now().Format("2006-01-02 15:04:05.000"),
Total: 0,
Data: "{}",
}
return d
}