-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.go
48 lines (40 loc) · 1.27 KB
/
repository.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
package main
import (
"database/sql"
_ "github.com/lib/pq"
)
type repository struct {
dbConx *sql.DB
}
func (r *repository) getSignupRecord(signupId int) (WorkshopSignupRecord, error) {
statement := "select w.title, concat(p.forename, ' ', p.surname) as name, r.role_name " +
"from people p join workshop_signups s on s.people_id = p.id " +
"join workshops w on s.workshop_id = w.id " +
"join roles r on s.role_id = r.id " +
"where s.id = $1"
row := r.dbConx.QueryRow(statement, signupId)
var record WorkshopSignupRecord
record.WorkshopSignupId = signupId
if err := row.Scan(&record.WorkshopTitle, &record.Name, &record.Role); err != nil {
return WorkshopSignupRecord{}, err
}
return record, nil
}
func (r *repository) getAttendeeNames(title string) []string {
statement := "select concat(p.forename, ' ', p.surname) as name " +
"from people p join workshop_signups s on s.people_id = p.id " +
"join workshops w on s.workshop_id = w.id " +
"join roles r on s.role_id = r.id " +
"where w.title = '$1' and r.role_name = 'attendee'"
rows, _ := r.dbConx.Query(statement, title)
var names []string
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
return []string{}
} else {
names = append(names, name)
}
}
return names
}