Remove inserts.go

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

View File

@ -1,33 +0,0 @@
package operations
import (
"database/sql"
)
func InsertCardStorageLocation(db *sql.DB, cardPrintingId string, isFoil bool, storageBox string, source string) error {
var lastPosition int
getLastPositionQuery := `SELECT Position FROM CardStorageLocation WHERE StorageBox = ? ORDER BY Position DESC LIMIT 1;`
err := db.QueryRow(getLastPositionQuery, storageBox).Scan(&lastPosition)
var nextPosition int
if err == sql.ErrNoRows {
nextPosition = 1
} else {
nextPosition = lastPosition + 1
}
insertQuery := `INSERT INTO CardStorageLocation
(CardPrintingId, IsFoil, StorageBox, Source, Position)
VALUES (?, ?, ?, ?, ?);`
insert, err := db.Prepare(insertQuery)
if err != nil {
return err
}
_, err = insert.Exec(cardPrintingId, isFoil, storageBox, source, nextPosition)
if err != nil {
return err
}
return nil
}