Skip to content

Commit

Permalink
Coalesce genre to null for smart playlist (#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Oct 31, 2023
1 parent 59f0c48 commit 77ace85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions model/criteria/criteria_test.go
Expand Up @@ -23,6 +23,7 @@ var _ = Describe("Criteria", func() {
All{
StartsWith{"comment": "this"},
InTheRange{"year": []int{1980, 1990}},
IsNot{"genre": "test"},
},
},
Sort: "title",
Expand All @@ -43,7 +44,8 @@ var _ = Describe("Criteria", func() {
},
{ "all": [
{ "startsWith": {"comment": "this"} },
{ "inTheRange": {"year":[1980,1990]} }
{ "inTheRange": {"year":[1980,1990]} },
{ "isNot": { "genre": "test" }}
]
}
],
Expand All @@ -62,8 +64,8 @@ var _ = Describe("Criteria", func() {
It("generates valid SQL", func() {
sql, args, err := goObj.ToSql()
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(sql).To(gomega.Equal("(media_file.title LIKE ? AND media_file.title NOT LIKE ? AND (media_file.artist <> ? OR media_file.album = ?) AND (media_file.comment LIKE ? AND (media_file.year >= ? AND media_file.year <= ?)))"))
gomega.Expect(args).To(gomega.ConsistOf("%love%", "%hate%", "u2", "best of", "this%", 1980, 1990))
gomega.Expect(sql).To(gomega.Equal("(media_file.title LIKE ? AND media_file.title NOT LIKE ? AND (media_file.artist <> ? OR media_file.album = ?) AND (media_file.comment LIKE ? AND (media_file.year >= ? AND media_file.year <= ?) AND COALESCE(genre.name, '') <> ?))"))
gomega.Expect(args).To(gomega.ConsistOf("%love%", "%hate%", "u2", "best of", "this%", 1980, 1990, "test"))
})

It("marshals to JSON", func() {
Expand Down
2 changes: 1 addition & 1 deletion model/criteria/fields.go
Expand Up @@ -40,7 +40,7 @@ var fieldMap = map[string]*mappedField{
"bitrate": {field: "media_file.bit_rate"},
"bpm": {field: "media_file.bpm"},
"channels": {field: "media_file.channels"},
"genre": {field: "genre.name"},
"genre": {field: "COALESCE(genre.name, '')"},
"loved": {field: "COALESCE(annotation.starred, false)"},
"dateloved": {field: "annotation.starred_at"},
"lastplayed": {field: "annotation.play_date"},
Expand Down

0 comments on commit 77ace85

Please sign in to comment.