Remove inserts.go
This commit is contained in:
parent
3cef5bea71
commit
deda3fc12d
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue