2024-05-29 19:55:38 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CardPrinting struct {
|
2024-06-03 16:08:15 +00:00
|
|
|
Id string
|
2024-05-29 19:55:38 +00:00
|
|
|
Name string
|
|
|
|
SetCode string
|
|
|
|
IsFoil bool
|
|
|
|
IsPromo bool
|
|
|
|
CollectorNumber string
|
2024-08-19 15:20:33 +00:00
|
|
|
ImageUrl string
|
2024-05-29 19:55:38 +00:00
|
|
|
Language string
|
|
|
|
}
|
|
|
|
|
|
|
|
func InsertCardPrinting(db *sql.DB, cardPrinting CardPrinting) error {
|
|
|
|
query := `INSERT INTO CardPrinting (
|
2024-06-03 16:08:15 +00:00
|
|
|
Id,
|
2024-05-29 19:55:38 +00:00
|
|
|
Name,
|
|
|
|
SetCode,
|
|
|
|
IsFoil,
|
|
|
|
IsPromo,
|
|
|
|
CollectorNumber,
|
2024-08-19 15:20:33 +00:00
|
|
|
ImageUrl,
|
2024-05-29 19:55:38 +00:00
|
|
|
Language)
|
2024-08-19 15:20:33 +00:00
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?);`
|
2024-05-29 19:55:38 +00:00
|
|
|
|
|
|
|
insert, err := db.Prepare(query)
|
|
|
|
defer insert.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-08-19 15:20:33 +00:00
|
|
|
_, err = insert.Exec(cardPrinting.Id, cardPrinting.Name, cardPrinting.SetCode, cardPrinting.IsFoil, cardPrinting.IsPromo, cardPrinting.CollectorNumber, cardPrinting.ImageUrl, cardPrinting.Language)
|
2024-05-29 19:55:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-05-30 13:32:04 +00:00
|
|
|
|
|
|
|
func GetAllCardPrintings(db *sql.DB) ([]CardPrinting, error) {
|
|
|
|
var cardPrintings []CardPrinting
|
|
|
|
|
|
|
|
query := `SELECT Id, Name, SetCode, IsFoil, IsPromo, CollectorNumber, Language FROM CardPrinting;`
|
|
|
|
rows, err := db.Query(query)
|
|
|
|
defer rows.Close()
|
|
|
|
if err != nil {
|
|
|
|
return cardPrintings, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var printing CardPrinting
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&printing.Id, &printing.Name, &printing.SetCode, &printing.IsFoil, &printing.IsPromo, &printing.CollectorNumber, &printing.Language)
|
|
|
|
if err != nil {
|
|
|
|
return cardPrintings, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cardPrintings = append(cardPrintings, printing)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cardPrintings, nil
|
|
|
|
}
|