TheMathemagicians/sevenkeys/database/cardstoragelocation.go

46 lines
946 B
Go
Raw Normal View History

package database
2024-06-01 21:18:33 +00:00
import (
"database/sql"
)
type CardLocation struct {
Id int
CardPrintingId string
StorageAreaId int
Position int
}
func GetLastPositionInStorageArea(db *sql.DB, storageAreaId int) (int, error) {
query := "SELECT Position FROM CardLocation WHERE StorageAreaId = ? ORDER BY Position DESC LIMIT 1;"
var lastPosition int
err := db.QueryRow(query, storageAreaId).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 InsertCardLocation(db *sql.DB, storageLocation CardLocation) error {
query := `INSERT INTO CardLocation
(CardPrintingId, StorageAreaId, Position)
VALUES (?, ?, ?);`
insert, err := db.Prepare(query)
if err != nil {
return err
}
_, err = insert.Exec(storageLocation.CardPrintingId, storageLocation.StorageAreaId, storageLocation.Position)
if err != nil {
return err
}
2024-05-30 13:33:37 +00:00
return nil
}