TheMathemagicians/sevenkeys/database/cardstoragelocation.go

47 lines
1022 B
Go
Raw Normal View History

package database
2024-06-01 21:18:33 +00:00
import (
"database/sql"
)
type CardStorageLocation struct {
Id int
CardPrintingId string
StorageBox string
Position int
Source string
}
func GetLastPositionInBox(db *sql.DB, storageBox string) (int, error) {
2024-06-01 21:18:33 +00:00
query := "SELECT Position FROM CardStorageLocation WHERE StorageBox = ? ORDER BY Position DESC LIMIT 1;"
var lastPosition int
2024-05-30 13:33:37 +00:00
err := db.QueryRow(query, storageBox).Scan(&lastPosition)
if err == sql.ErrNoRows {
return 0, nil
2024-06-01 21:18:33 +00:00
} else if err != nil {
return 0, err
}
return lastPosition, nil
}
func InsertCardStorageLocation(db *sql.DB, storageLocation CardStorageLocation) error {
query := `INSERT INTO CardStorageLocation
(CardPrintingId, StorageBox, Position, Source)
VALUES (?, ?, ?, ?);`
insert, err := db.Prepare(query)
if err != nil {
return err
}
_, err = insert.Exec(storageLocation.CardPrintingId, storageLocation.StorageBox, storageLocation.Position, storageLocation.Source)
if err != nil {
return err
}
2024-05-30 13:33:37 +00:00
return nil
}