Skip to content

Commit c158912

Browse files
nadiamoenkanaev
authored andcommitted
fix media_links reading from DB
Prior to this commit, `MediaLinks` were always returned as `nil`. Peeking a bit I figured that's becuase the argument to `MediaLinks.Scan` is in fact a string, and not a `[]byte` as the code expects. I guess that might be because `media_links` is a `json` (not `jsonb`) column in sqlite. I have no idea which of the two is best to use for the DB side, but it's easy to make the code support both.
1 parent 08ad044 commit c158912

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/storage/item.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ type MediaLink struct {
5454
type MediaLinks []MediaLink
5555

5656
func (m *MediaLinks) Scan(src any) error {
57-
if data, ok := src.([]byte); ok {
57+
switch data := src.(type) {
58+
case []byte:
5859
return json.Unmarshal(data, m)
60+
case string:
61+
return json.Unmarshal([]byte(data), m)
62+
default:
63+
return nil
5964
}
60-
return nil
6165
}
6266

6367
func (m MediaLinks) Value() (driver.Value, error) {
@@ -419,7 +423,6 @@ func (s *Storage) DeleteOldItems() {
419423
where status != ?
420424
group by i.feed_id
421425
`, itemsKeepSize, STARRED)
422-
423426
if err != nil {
424427
log.Print(err)
425428
return

0 commit comments

Comments
 (0)