-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_companies.go
53 lines (47 loc) · 1.15 KB
/
db_companies.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
package main
import "fmt"
type DbCompany struct {
Id uint `json:"id"`
IgdbId uint `json:"igdb_id"`
Name string `json:"name"`
}
func (db DbClient) GetCompany(igdbId int) DbCompany {
var company DbCompany
err := db.instance.QueryRow(
"SELECT id, name FROM companies WHERE igdb_id = ?", igdbId,
).Scan(
&company.Id,
&company.Name,
)
if err != nil {
panic(err.Error())
}
return company
}
func (db DbClient) GetCompanyById(id int64) DbCompany {
var company DbCompany
err := db.instance.QueryRow("SELECT name FROM companies WHERE id = ?", id).Scan(&company.Name)
if err != nil {
panic(err.Error())
}
return company
}
func (db DbClient) AddCompany(company DbCompany) {
query := fmt.Sprintf("INSERT INTO companies (igdb_id, name, created_at) VALUES (%d, \"%s\", NOW())",
company.IgdbId,
company.Name,
)
insert, err := db.instance.Query(query)
if err != nil {
panic(err.Error())
}
defer insert.Close()
}
func (db DbClient) CompanyExists(igdbId int) bool {
var company DbCompany
err := db.instance.QueryRow("SELECT name FROM companies WHERE igdb_id = ?", igdbId).Scan(&company.Name)
if err != nil {
return false
}
return true
}