refactor(database): clean-up queries (#569)

* fix(database): build WHERE using squirrel

* flip LIKEs

* change sql.LevelReadCommitted

* feat(db): add missing commits

* implement single query for releases

* cleanup

* feat(releases): properly handle limit for Find

* feat(releases): make dynamic ILike helper

* feat(releases): check for empty ReleaseActionStatus

* add values as sql.NullX
* check if ID is non 0

* feat(releases): improve find
This commit is contained in:
Kyle Sanderson 2022-12-30 14:53:45 -08:00 committed by GitHub
parent e6c48a5228
commit 19b3899a5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 206 additions and 168 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/autobrr/autobrr/internal/logger"
"github.com/autobrr/autobrr/pkg/errors"
sq "github.com/Masterminds/squirrel"
"github.com/rs/zerolog"
)
@ -136,7 +137,7 @@ func (r *DownloadClientRepo) FindByID(ctx context.Context, id int32) (*domain.Do
"settings",
).
From("client").
Where("id = ?", id)
Where(sq.Eq{"id": id})
query, args, err := queryBuilder.ToSql()
if err != nil {
@ -232,7 +233,7 @@ func (r *DownloadClientRepo) Update(ctx context.Context, client domain.DownloadC
Set("username", client.Username).
Set("password", client.Password).
Set("settings", string(settingsJson)).
Where("id = ?", client.ID)
Where(sq.Eq{"id": client.ID})
query, args, err := queryBuilder.ToSql()
if err != nil {
@ -255,7 +256,7 @@ func (r *DownloadClientRepo) Update(ctx context.Context, client domain.DownloadC
func (r *DownloadClientRepo) Delete(ctx context.Context, clientID int) error {
queryBuilder := r.db.squirrel.
Delete("client").
Where("id = ?", clientID)
Where(sq.Eq{"id": clientID})
query, args, err := queryBuilder.ToSql()
if err != nil {