/
helper.go
137 lines (113 loc) · 2.5 KB
/
helper.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package db
import "github.com/jmoiron/sqlx"
type Helper interface {
SQL() SqlStmts
InitSQL() []string
CreateWithID(tx *sqlx.Tx, sql string, arg interface{}) (int64, error)
Upgrade(db *DB, old, new int) error
WhereMultipleORs(string, string, int, bool) string
RetryableErr(err error) bool
}
type ArticleStmts struct {
Create string
Update string
GetUserlessTemplate string
GetTemplate string
CountTemplate string
CountUserFeedsJoin string
StateReadColumn string
StateUnreadJoin string
StateFavoriteJoin string
GetIDsTemplate string
DeleteStaleUnreadRecords string
GetScoreJoin string
GetUntaggedJoin string
ReadStateInsertTemplate string
ReadStateDeleteTemplate string
FavoriteStateInsertTemplate string
FavoriteStateDeleteTemplate string
}
type ExtractStmts struct {
Get string
Create string
Update string
}
type FeedStmts struct {
Get string
GetByLink string
GetForUser string
All string
AllForUser string
AllForTag string
Unsubscribed string
IDs string
Create string
Update string
Delete string
GetUsers string
Attach string
Detach string
CreateUserTag string
DeleteUserTags string
}
type ScoresStmts struct {
Get string
Create string
Update string
}
type SubscriptionStmts struct {
GetForFeed string
All string
Create string
Update string
}
type TagStmts struct {
Get string
GetByValue string
AllForUser string
AllForFeed string
Create string
GetUserFeedIDs string
DeleteStale string
}
type ThumbnailStmts struct {
Get string
Create string
Update string
}
type UserStmts struct {
Get string
GetByMD5API string
All string
Create string
Update string
Delete string
}
type SqlStmts struct {
Article ArticleStmts
Extract ExtractStmts
Feed FeedStmts
Scores ScoresStmts
Subscription SubscriptionStmts
Tag TagStmts
Thumbnail ThumbnailStmts
User UserStmts
}
func Register(driver string, helper Helper) {
if helper == nil {
panic("No helper provided")
}
if _, ok := helpers[driver]; ok {
panic("Helper " + driver + " already registered")
}
helpers[driver] = helper
}
// Can't recover from missing driver or statement, panic
func (db DB) SQL() SqlStmts {
driver := db.DriverName()
if h, ok := helpers[driver]; ok {
return h.SQL()
} else {
panic("No helper registered for " + driver)
}
}