Add CardStrorageLocation database operations

This commit is contained in:
The Magician 2024-05-30 13:03:12 +01:00
parent ea2227e1b1
commit 3cef5bea71
1 changed files with 42 additions and 0 deletions

View File

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