64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
type CardPrinting struct {
|
|
Id string
|
|
Name string
|
|
SetCode string
|
|
IsFoil bool
|
|
IsPromo bool
|
|
CollectorNumber string
|
|
Language string
|
|
}
|
|
|
|
func InsertCardPrinting(db *sql.DB, cardPrinting CardPrinting) error {
|
|
query := `INSERT INTO CardPrinting (
|
|
Id,
|
|
Name,
|
|
SetCode,
|
|
IsFoil,
|
|
IsPromo,
|
|
CollectorNumber,
|
|
Language)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?);`
|
|
|
|
insert, err := db.Prepare(query)
|
|
defer insert.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = insert.Exec(cardPrinting.Id, cardPrinting.Name, cardPrinting.SetCode, cardPrinting.IsFoil, cardPrinting.IsPromo, cardPrinting.CollectorNumber, cardPrinting.Language)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
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
|
|
}
|