Question

In my Play2 app, I am trying to retrieve a list of users from one of my database table. The query responsible for this may potentially be empty if there is no row in the database matching the criteria (which is the firstName in our case). That is why I have managed to implement it like this :

    DB.withConnection { implicit connection =>
      SQL("""select u.* from users u
                where u.firstName like '%{firstName}%'
          """).on("firstName" -> firstName).as(userParser *)
    }

this query returns a List[User] but how can I return an Option[List[User]] since this query may not retrieve data corresponding to the provided param (firstName) ?

any help would be appreciated thanks...

Was it helpful?

Solution

You don't need to. If no user is found. The list will simply be empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top