What is the proper way of finding the one User matching username?
With user-defined type User:
case class User (userId: String, username: String)
object User extends Table[User]("user") {
def userId = column[String]("userId", O.PrimaryKey)
def username = column[String]("username")
def * = userId ~ authId ~ username <>(User.apply _, User.unapply _)
Database.forDataSource(DB.getDataSource()) withSession {
implicit session: Session =>
val q = for { u <- User if u.username.equalsIgnoreCase(someUsername) }
yield u
q.headOption
user.username is of type Column[String] which has no conversion to String.
What is desired is to have the Database do the string-insensitive comparison as part of the query.
Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function. Example 1: This example uses toUpperCase() function to compare two strings.
strcasecmp() — Case-insensitive string comparison.
CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.
Case-insensitive: It means the text or typed input that is not sensitive to capitalization of letters, like “Geeks” and “GEEKS” must be treated as same in case-insensitive search. In Javascript, we use string. match() function to search a regexp in a string and match() function returns the matches, as an Array object.
I had a similar situation and solved it by using toLowerCase
extension method:
p <- u.party if p.loginName.toLowerCase === partyName.toLowerCase
You can find here more extension methods, especially String ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With