mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
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:
parent
e6c48a5228
commit
19b3899a5c
12 changed files with 206 additions and 168 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue