-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.go
57 lines (42 loc) · 1.1 KB
/
label.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
package main
import (
"database/sql"
"fmt"
)
type Label struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Color string `json:"color,omitempty"`
RepoId string `json:"repo_id,omitempty"`
}
func GetLabel(db *sql.DB, Id int) (Label, error) {
var name, description, color string
row := db.QueryRow("SELECT name, description, color FROM labels WHERE id=$1", Id)
err := row.Scan(&name, &description, &color)
if err != nil {
return Label{}, err
}
label := Label{
ID: Id,
Name: name,
Description: description,
Color: color,
}
return label, nil
}
func CreateLabel(db *sql.DB, label Label) error {
_, err := db.Exec(`INSERT INTO labels ( name, description,color ,repo_id) VALUES ( $1, $2, $3,$4 ) `, label.Name, label.Description, label.Color, label.RepoId)
if err != nil {
fmt.Println(err)
return err
}
return nil
}
func DeleteLabel(db *sql.DB, id int) error {
_, err := db.Exec(`DELETE FROM labels WHERE id = $1`, id)
if err != nil {
return err
}
return nil
}