refactor: extract scanContinueWatchingEntry helper
This commit is contained in:
@@ -48,8 +48,22 @@ LIMIT ?`, userID, needle, pattern, pattern, pattern, pattern, limit)
|
|||||||
|
|
||||||
items := make([]GetContinueWatchingEntriesRow, 0, int(limit))
|
items := make([]GetContinueWatchingEntriesRow, 0, int(limit))
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
item, err := scanContinueWatchingEntry(rows)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, item)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanContinueWatchingEntry(rows scanner) (GetContinueWatchingEntriesRow, error) {
|
||||||
var item GetContinueWatchingEntriesRow
|
var item GetContinueWatchingEntriesRow
|
||||||
if err := rows.Scan(
|
err := rows.Scan(
|
||||||
&item.ID,
|
&item.ID,
|
||||||
&item.UserID,
|
&item.UserID,
|
||||||
&item.AnimeID,
|
&item.AnimeID,
|
||||||
@@ -63,16 +77,8 @@ LIMIT ?`, userID, needle, pattern, pattern, pattern, pattern, limit)
|
|||||||
&item.TitleJapanese,
|
&item.TitleJapanese,
|
||||||
&item.ImageUrl,
|
&item.ImageUrl,
|
||||||
&item.AnimeDurationSeconds,
|
&item.AnimeDurationSeconds,
|
||||||
); err != nil {
|
)
|
||||||
return nil, err
|
return item, err
|
||||||
}
|
|
||||||
items = append(items, item)
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return items, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]GetUserWatchListRow, error) {
|
func (q *Queries) GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]GetUserWatchListRow, error) {
|
||||||
@@ -158,3 +164,7 @@ func commandPalettePattern(query string) (string, string) {
|
|||||||
needle := strings.ToLower(strings.TrimSpace(query))
|
needle := strings.ToLower(strings.TrimSpace(query))
|
||||||
return needle, "%" + needle + "%"
|
return needle, "%" + needle + "%"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type scanner interface {
|
||||||
|
Scan(dest ...interface{}) error
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user