From 425b43b3bb6376d3dafcabfe3142705e7c9e8bd0 Mon Sep 17 00:00:00 2001 From: Athurg Gooth Date: Mon, 9 Oct 2023 14:40:54 +0800 Subject: [PATCH] fix: ListTag not support omit params (#2366) fix ListTag not support omit params --- store/db/mysql/tag.go | 7 ++++++- store/db/sqlite/tag.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/store/db/mysql/tag.go b/store/db/mysql/tag.go index e7ab173e..ccfe8093 100644 --- a/store/db/mysql/tag.go +++ b/store/db/mysql/tag.go @@ -18,7 +18,12 @@ func (d *DB) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, erro } func (d *DB) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) { - where, args := []string{"`creator_id` = ?"}, []any{find.CreatorID} + where, args := []string{"1 = 1"}, []any{} + + if find.CreatorID != 0 { + where, args = append(where, "`creator_id` = ?"), append(args, find.CreatorID) + } + query := "SELECT `name`, `creator_id` FROM `tag` WHERE " + strings.Join(where, " AND ") + " ORDER BY name ASC" rows, err := d.db.QueryContext(ctx, query, args...) if err != nil { diff --git a/store/db/sqlite/tag.go b/store/db/sqlite/tag.go index fce43c5a..2c6d313f 100644 --- a/store/db/sqlite/tag.go +++ b/store/db/sqlite/tag.go @@ -27,7 +27,12 @@ func (d *DB) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, erro } func (d *DB) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) { - where, args := []string{"creator_id = ?"}, []any{find.CreatorID} + where, args := []string{"1 = 1"}, []any{} + + if find.CreatorID != 0 { + where, args = append(where, "`creator_id` = ?"), append(args, find.CreatorID) + } + query := ` SELECT name,