-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.go
62 lines (52 loc) · 2.68 KB
/
operations.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
package db
import (
"database/sql"
)
func DbGetMailRequests(id int, offset, pageSize int, db *sql.DB) (*sql.Rows, error) {
var query string
var args []interface{}
if offset < 0 || pageSize < 0 {
query = "SELECT n2mr.id, n2mr.inserttime, n2mr.updatetime, n2mr.mail_config FROM not2_mail_request n2mr JOIN not2_request n2r ON n2mr.request_id = n2r.id WHERE n2r.not_user=$1"
args = append(args, id)
} else {
query = "SELECT n2mr.id, n2mr.inserttime, n2mr.updatetime, n2mr.mail_config FROM not2_mail_request n2mr JOIN not2_request n2r ON n2mr.request_id = n2r.id WHERE n2r.not_user=$1 OFFSET $2 LIMIT $3"
args = append(args, id, offset, pageSize)
}
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
return rows, err
}
func DbGetMailItemsByRequest(uid string, id int, offset, pageSize int, db *sql.DB) (*sql.Rows, error) {
var query string
var args []interface{}
if offset < 0 || pageSize < 0 {
query = "SELECT item.message_id, item.state, item.inserttime, item.updatetime, item.receiver, n2mr.mail_config FROM not2_mail_item item JOIN not2_mail_request n2mr ON n2mr.id = item.mail_request JOIN not2_request n2r ON n2mr.request_id = n2r.id WHERE n2r.notification_id =$1 AND n2r.not_user =$2"
args = append(args, uid, id)
} else {
query = "SELECT item.message_id, item.state, item.inserttime, item.updatetime, item.receiver, n2mr.mail_config FROM not2_mail_item item JOIN not2_mail_request n2mr ON n2mr.id = item.mail_request JOIN not2_request n2r ON n2mr.request_id = n2r.id WHERE n2r.notification_id =$1 AND n2r.not_user =$2 OFFSET $3 LIMIT $4"
args = append(args, uid, id, offset, pageSize)
}
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
return rows, err
}
func DbGetMailItemsByMailConfigId(confId int, id int, offset, pageSize int, db *sql.DB) (*sql.Rows, error) {
var query string
var args []interface{}
if offset < 0 || pageSize < 0 {
query = "SELECT item.message_id, item.state, item.inserttime, item.updatetime, item.receiver, n2mr.mail_config FROM not2_mail_item item JOIN not2_mail_request n2mr on item.mail_request = n2mr.id JOIN not2_request n2r on n2mr.request_id = n2r.id WHERE n2mr.mail_config =$1 and n2r.not_user = $2"
args = append(args, confId, id)
} else {
query = "SELECT item.message_id, item.state, item.inserttime, item.updatetime, item.receiver, n2mr.mail_config FROM not2_mail_item item JOIN not2_mail_request n2mr on item.mail_request = n2mr.id JOIN not2_request n2r on n2mr.request_id = n2r.id WHERE n2mr.mail_config =$1 and n2r.not_user = $2 OFFSET $3 LIMIT $4"
args = append(args, confId, id, offset, pageSize)
}
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
return rows, err
}