Fix Genre field and Contains/NotContains/StartsWith/EndsWith in Criteria (Smart Playlists)

This commit is contained in:
Deluan 2021-10-25 16:17:03 -04:00
parent 47549ecfc1
commit 93ce0b5683
4 changed files with 12 additions and 10 deletions

View file

@ -62,7 +62,7 @@ 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 ILIKE ? AND media_file.title NOT ILIKE ? AND (media_file.artist <> ? OR media_file.album = ?) AND (media_file.comment ILIKE ? AND (media_file.year >= ? AND media_file.year <= ?)))"))
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))
})

View file

@ -99,7 +99,7 @@ func (af After) MarshalJSON() ([]byte, error) {
type Contains map[string]interface{}
func (ct Contains) ToSql() (sql string, args []interface{}, err error) {
lk := squirrel.ILike{}
lk := squirrel.Like{}
for f, v := range mapFields(ct) {
lk[f] = fmt.Sprintf("%%%s%%", v)
}
@ -113,7 +113,7 @@ func (ct Contains) MarshalJSON() ([]byte, error) {
type NotContains map[string]interface{}
func (nct NotContains) ToSql() (sql string, args []interface{}, err error) {
lk := squirrel.NotILike{}
lk := squirrel.NotLike{}
for f, v := range mapFields(nct) {
lk[f] = fmt.Sprintf("%%%s%%", v)
}
@ -127,7 +127,7 @@ func (nct NotContains) MarshalJSON() ([]byte, error) {
type StartsWith map[string]interface{}
func (sw StartsWith) ToSql() (sql string, args []interface{}, err error) {
lk := squirrel.ILike{}
lk := squirrel.Like{}
for f, v := range mapFields(sw) {
lk[f] = fmt.Sprintf("%s%%", v)
}
@ -141,7 +141,7 @@ func (sw StartsWith) MarshalJSON() ([]byte, error) {
type EndsWith map[string]interface{}
func (sw EndsWith) ToSql() (sql string, args []interface{}, err error) {
lk := squirrel.ILike{}
lk := squirrel.Like{}
for f, v := range mapFields(sw) {
lk[f] = fmt.Sprintf("%%%s", v)
}

View file

@ -25,10 +25,10 @@ var _ = Describe("Operators", func() {
Entry("isNot", IsNot{"title": "Low Rider"}, "media_file.title <> ?", "Low Rider"),
Entry("gt", Gt{"playCount": 10}, "annotation.play_count > ?", 10),
Entry("lt", Lt{"playCount": 10}, "annotation.play_count < ?", 10),
Entry("contains", Contains{"title": "Low Rider"}, "media_file.title ILIKE ?", "%Low Rider%"),
Entry("notContains", NotContains{"title": "Low Rider"}, "media_file.title NOT ILIKE ?", "%Low Rider%"),
Entry("startsWith", StartsWith{"title": "Low Rider"}, "media_file.title ILIKE ?", "Low Rider%"),
Entry("endsWith", EndsWith{"title": "Low Rider"}, "media_file.title ILIKE ?", "%Low Rider"),
Entry("contains", Contains{"title": "Low Rider"}, "media_file.title LIKE ?", "%Low Rider%"),
Entry("notContains", NotContains{"title": "Low Rider"}, "media_file.title NOT LIKE ?", "%Low Rider%"),
Entry("startsWith", StartsWith{"title": "Low Rider"}, "media_file.title LIKE ?", "Low Rider%"),
Entry("endsWith", EndsWith{"title": "Low Rider"}, "media_file.title LIKE ?", "%Low Rider"),
Entry("inTheRange [number]", InTheRange{"year": []int{1980, 1990}}, "(media_file.year >= ? AND media_file.year <= ?)", 1980, 1990),
Entry("inTheRange [date]", InTheRange{"lastPlayed": []Time{rangeStart, rangeEnd}}, "(annotation.play_date >= ? AND annotation.play_date <= ?)", rangeStart, rangeEnd),
Entry("before", Before{"lastPlayed": rangeStart}, "annotation.play_date < ?", rangeStart),