Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batchGet #19

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badge
column名間違ってました、、
すみませんありがとうございます!!🙇

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
Loading