summaryrefslogtreecommitdiff
path: root/model/mysql/queries.go
blob: e579df721c91c49123d047500e1d50d2d8addcb2 (plain)
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
package mysql

const (
	qUserByID = iota
	qUserByEmail
	qSetPWHash
	qSetActive
	qSetAcCode
	qDelUsersJobs
	qDelUser
	qGetOldInactiveUsers
	qCountJobs
	qJobsOfUser
	qJobFromUserAndID
	qSetSubject
	qSetContent
	qSetNext
	qDelJob
	qJobsBefore
	qInsertJob
	qInsertUser
	qSetChronos
	qSetLocation
	qEnd
)

const (
	qfragSelUser = "SELECT `id`, `email`, `passwd`, `location`, `active`, `activationcode`, `added` FROM `users` "
	qfragSelJob  = "SELECT `id`, `user`, `subject`, `content`, `next`, `chronos` FROM `jobs` "
)

var queries = map[int]string{
	qUserByID:            qfragSelUser + "WHERE `id` = ?",
	qUserByEmail:         qfragSelUser + "WHERE `email` = ?",
	qSetPWHash:           "UPDATE `users` SET `passwd` = ? WHERE `id` = ?",
	qSetActive:           "UPDATE `users` SET `active` = ? WHERE `id` = ?",
	qSetAcCode:           "UPDATE `users` SET `activationcode` = ? WHERE `id` = ?",
	qDelUsersJobs:        "DELETE FROM `jobs` WHERE `user` = ?",
	qDelUser:             "DELETE FROM `users` WHERE `id` = ?",
	qGetOldInactiveUsers: "SELECT `id` FROM `users` WHERE `active` = 0 AND `added` < ?",
	qCountJobs:           "SELECT COUNT(*) FROM `jobs` WHERE `user` = ?",
	qJobsOfUser:          qfragSelJob + "WHERE `user` = ?",
	qJobFromUserAndID:    qfragSelJob + "WHERE `user` = ? AND `id` = ?",
	qSetSubject:          "UPDATE `jobs` SET `subject` = ? WHERE `id` = ?",
	qSetContent:          "UPDATE `jobs` SET `content` = ? WHERE `id` = ?",
	qSetNext:             "UPDATE `jobs` SET `next` = ? WHERE `id` = ?",
	qDelJob:              "DELETE FROM `jobs` WHERE `id` = ?",
	qJobsBefore:          qfragSelJob + "WHERE `next` <= ?",
	qInsertJob:           "INSERT INTO `jobs` (`user`, `subject`, `content`, `next`, `chronos`) VALUES (?, ?, ?, ?, ?)",
	qInsertUser:          "INSERT INTO `users` (`email`, `passwd`, `location`, `active`, `activationcode`, `added`) VALUES (?, ?, ?, ?, ?, ?)",
	qSetChronos:          "UPDATE `jobs` SET `chronos` = ? WHERE `id` = ?",
	qSetLocation:         "UPDATE `users` SET `location` = ? WHERE `id` = ?",
}