-
Notifications
You must be signed in to change notification settings - Fork 0
/
reading.go
65 lines (41 loc) · 1.11 KB
/
reading.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
package models
import (
"time"
// "github.com/go-gorp/gorp"
"gopkg.in/gorp.v1"
)
type Reading struct {
// Open library fields
// Fields found so far
// subtitle
// covers
// latest_revision, revision
// subject_times
// subjects
Title string `json:"title"`
// OL key e.g. "/works/OL10000223W"
Key string `json:"key"`
// cover ids e.g. [3140972]
// get at http://covers.openlibrary.org/b/id/{id}-[S|M|L].jpg
Cover int `json:"cover"` //db:"covers,size:1024"
// TODO Authors - likely a join table
// our extra fields
IsBook bool `json:"is_book"`
// Meta
Id int64 `db:"id" json:"id"`
CreatedAt int64 `db:"created_at" json:"created_at"`
UpdatedAt int64 `db:"updated_at" json:"updated_at"`
}
/*
* SQL Hooks
*/
// implement the PreInsert and PreUpdate hooks
func (i *Reading) PreInsert(s gorp.SqlExecutor) error {
i.CreatedAt = time.Now().UnixNano()
i.UpdatedAt = i.CreatedAt
return nil
}
func (i *Reading) PreUpdate(s gorp.SqlExecutor) error {
i.UpdatedAt = time.Now().UnixNano()
return nil
}