-
Notifications
You must be signed in to change notification settings - Fork 0
/
footballer.go
50 lines (40 loc) · 1.1 KB
/
footballer.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
package main
import (
"database/sql"
"errors"
)
type footballer struct {
Id int `json:"id"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
Position string `json:"position"`
ClubId int `json:"clubid"`
}
func (p *footballer) getFootballer(db *sql.DB) error {
return errors.New("Not implemented")
}
func (p *footballer) updateFootballer(db *sql.DB) error {
return errors.New("Not implemented")
}
func (p *footballer) deleteFootballer(db *sql.DB) error {
return errors.New("Not implemented")
}
func (p *footballer) createFootballer(db *sql.DB) error {
return errors.New("Not implemented")
}
func getFootballers(db *sql.DB) ([]footballer, error) {
rows, err := db.Query("SELECT id, firstname, lastname, position, clubid FROM footballer")
if err != nil {
return nil, err
}
defer rows.Close()
players := []footballer{}
for rows.Next() {
var player footballer
if err := rows.Scan(&player.Id, &player.FirstName, &player.LastName, &player.Position, &player.ClubId); err != nil {
return nil, err
}
players = append(players, player)
}
return players, nil
}