TheMathemagicians/sevenkeys/database/remove.go

51 lines
1000 B
Go
Raw Normal View History

2024-09-12 12:37:41 +00:00
package database
import "database/sql"
2024-09-13 11:32:18 +00:00
func RemoveFromBinder(db *sql.DB, location LocateCardResult) error {
2024-09-12 12:37:41 +00:00
query := `UPDATE CardStorageLocation SET CardPrintingId = NULL WHERE Id = ?;`
update, err := db.Prepare(query)
defer update.Close()
if err != nil {
return err
}
2024-09-13 11:32:18 +00:00
_, err = update.Exec(location.CardLocationId)
2024-09-12 12:37:41 +00:00
if err != nil {
return err
}
return nil
}
2024-09-13 11:32:18 +00:00
func RemoveFromBox(db *sql.DB, location LocateCardResult) error {
2024-09-12 12:37:41 +00:00
deleteQuery := `DELETE FROM CardStorageLocation WHERE Id = ?;`
del, err := db.Prepare(deleteQuery)
defer del.Close()
if err != nil {
return err
}
2024-09-13 11:32:18 +00:00
_, err = del.Exec(location.CardLocationId)
2024-09-12 12:37:41 +00:00
if err != nil {
return err
}
2024-09-13 11:32:18 +00:00
updateQuery := `UPDATE CardStorageLocation SET Position = Position - 1 WHERE Position > ? AND StorageAreaId = ?;`
2024-09-12 12:37:41 +00:00
update, err := db.Prepare(updateQuery)
defer update.Close()
if err != nil {
return err
}
2024-09-13 11:32:18 +00:00
_, err = update.Exec(location.Position, location.StorageAreaId)
2024-09-12 12:37:41 +00:00
if err != nil {
return err
}
return nil
}