mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Improve field query and fix mariadb's pickiness with parens
If no query is given, don't search with `like '%'`. MariaDB doesn't want parens around columns in the GROUP BY clause.
This commit is contained in:
@ -13,7 +13,7 @@ trait DoobieSyntax {
|
||||
groupBy(NonEmptyList.of(c0, cs: _*))
|
||||
|
||||
def groupBy(cs: NonEmptyList[Column]): Fragment =
|
||||
fr" GROUP BY (" ++ commas(cs.toList.map(_.f)) ++ fr")"
|
||||
fr" GROUP BY " ++ commas(cs.toList.map(_.f))
|
||||
|
||||
def coalesce(f0: Fragment, fs: Fragment*): Fragment =
|
||||
sql" coalesce(" ++ commas(f0 :: fs.toList) ++ sql") "
|
||||
|
@ -42,7 +42,7 @@ object QCustomField {
|
||||
|
||||
val nameCond = nameQuery.map(QueryWildcard.apply) match {
|
||||
case Some(q) =>
|
||||
or(fName.lowerLike(q), fLabel.lowerLike(q))
|
||||
or(fName.lowerLike(q), and(fLabel.isNotNull, fLabel.lowerLike(q)))
|
||||
case None =>
|
||||
Fragment.empty
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ object QueryWildcard {
|
||||
if (n.endsWith("*")) s"${n.dropRight(1)}%"
|
||||
else n
|
||||
|
||||
prefix(suffix(value))
|
||||
val res = prefix(suffix(value))
|
||||
if (res == "%%") "%"
|
||||
else res
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,4 +18,9 @@ object QueryWildcardTest extends SimpleTestSuite {
|
||||
assertEquals("%name%", QueryWildcard("*name*"))
|
||||
assertEquals("%some other name%", QueryWildcard("*some other name*"))
|
||||
}
|
||||
|
||||
test("do not use multiple wildcards") {
|
||||
assertEquals("%", QueryWildcard("**"))
|
||||
assertEquals("%*%", QueryWildcard("***"))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user