sql: Refactor use of tables

This commit is contained in:
Tom Wiesing 2023-01-09 10:24:24 +01:00
parent 85fe5b5c5a
commit 73d821e320
No known key found for this signature in database
19 changed files with 191 additions and 83 deletions

View file

@ -3,7 +3,6 @@ package bookkeeping
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
)
@ -14,7 +13,7 @@ type Bookkeeping struct {
// Save saves this instance in the bookkeeping table
func (bk *Bookkeeping) Save(ctx context.Context) error {
sdb, err := bk.Malt.SQL.QueryTable(ctx, false, models.InstanceTable)
sdb, err := bk.Malt.SQL.QueryTable(ctx, bk.Malt.InstanceTable)
if err != nil {
return err
}
@ -30,7 +29,7 @@ func (bk *Bookkeeping) Save(ctx context.Context) error {
// Delete deletes this instance from the bookkeeping table
func (bk *Bookkeeping) Delete(ctx context.Context) error {
sdb, err := bk.Malt.SQL.QueryTable(ctx, false, models.InstanceTable)
sdb, err := bk.Malt.SQL.QueryTable(ctx, bk.Malt.InstanceTable)
if err != nil {
return err
}

View file

@ -16,7 +16,7 @@ type Locker struct {
}
var (
_ = (ingredient.WissKIFetcher)((*Locker)(nil))
_ ingredient.WissKIFetcher = (*Locker)(nil)
)
var Locked = exit.Error{
@ -26,7 +26,7 @@ var Locked = exit.Error{
// TryLock attemps to lock this WissKI and returns if it suceeded
func (lock *Locker) TryLock(ctx context.Context) bool {
table, err := lock.Malt.SQL.QueryTable(ctx, true, models.LockTable)
table, err := lock.Malt.SQL.QueryTable(ctx, lock.Malt.LockTable)
if err != nil {
return false
}
@ -41,7 +41,7 @@ func (lock *Locker) TryUnlock(ctx context.Context) bool {
ctx, close := cancel.Anyways(ctx, time.Second)
defer close()
table, err := lock.Malt.SQL.QueryTable(ctx, true, models.LockTable)
table, err := lock.Malt.SQL.QueryTable(ctx, lock.Malt.LockTable)
if err != nil {
return false
}

View file

@ -3,7 +3,6 @@ package locker
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
)
@ -11,7 +10,7 @@ import (
// Locked checks if this WissKI is currently locked.
// If an error occurs, the instance is considered not locked.
func (lock *Locker) Locked(ctx context.Context) (locked bool) {
table, err := lock.SQL.QueryTable(ctx, true, models.LockTable)
table, err := lock.Malt.SQL.QueryTable(ctx, lock.Malt.LockTable)
if err != nil {
return false
}