Skip to content

Commit

Permalink
fix: batchGet
Browse files Browse the repository at this point in the history
  • Loading branch information
MasatoraAtarashi committed Feb 8, 2024
1 parent 874288d commit 5b9aa28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
15 changes: 11 additions & 4 deletions pkg/repository/database/season.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,27 @@ func (e *Season) BatchGet(ctx context.Context, ids []string) (entity.Seasons, er
strings.Join(fields, ","),
strings.Repeat(",?", len(newIDs)-1),
)
rows, err := e.db.QueryContext(ctx, query, newIDs)
rows, err := e.db.QueryContext(ctx, query, convertStringsToAnys(newIDs)...)
if err != nil {
return nil, errcode.New(err)
}

var seasons entity.Seasons
var multiErr error
for rows.Next() {
var s entity.Season
if err = rows.Scan(&s); err != nil {
season := &entity.Season{}
err = rows.Scan(
&season.ID,
&season.SeriesID,
&season.DisplayName,
&season.ImageURL,
&season.DisplayOrder,
)
if err != nil {
multiErr = multierr.Append(multiErr, err)
continue
}
seasons = append(seasons, &s)
seasons = append(seasons, season)
}

if cerr := rows.Close(); cerr != nil {
Expand Down
20 changes: 15 additions & 5 deletions pkg/repository/database/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,34 @@ func (e *Series) BatchGet(ctx context.Context, ids []string) (entity.SeriesMulti
}
}

fields := []string{"id", "displayName", "description", "imageUrl", "genreId"}
fields := []string{"seriesID", "displayName", "description", "imageURL", "genreID"}
query := fmt.Sprintf(
"SELECT %s FROM series WHERE seriesID IN(?%s)",
strings.Join(fields, ", "),
strings.Repeat(",?", len(newIDs)-1),
)

rows, err := e.db.QueryContext(ctx, query, newIDs)
rows, err := e.db.QueryContext(ctx, query, convertStringsToAnys(newIDs)...)
if err != nil {
return nil, errcode.New(err)
}

var seriesMulti entity.SeriesMulti
var multiErr error
for rows.Next() {
var series entity.Series
if err := rows.Scan(&series); err != nil {
series := &entity.Series{}
err = rows.Scan(
&series.ID,
&series.DisplayName,
&series.Description,
&series.ImageURL,
&series.GenreID,
)
if err != nil {
multiErr = multierr.Append(multiErr, err)
continue
}
seriesMulti = append(seriesMulti, &series)
seriesMulti = append(seriesMulti, series)
}

if err := rows.Close(); err != nil {
Expand Down

0 comments on commit 5b9aa28

Please sign in to comment.