# exposed


09/24/2018, 8:59 PM
How can I get a table object's contains operator to differentiate between parameters corresponding to different fields that are both strings? I'm currently writing out different classes for each string to accomplish this, but if there's an easier way, i'm all ears. e.g.
Copy code
operator fun contains(username: String): Boolean = UserEntity.find { self.username eq username }.count() > 0
operator fun contains(email: Email): Boolean = UserEntity.find { eq email }.count() > 0
also if there's a more efficient way to write a contains function, i wouldn't be surprised in the slightest


09/25/2018, 8:07 AM
count could be very slow if you dont have index or table has a lot of records. I prefer :
select { eq email }.limit(1).any()
👍 1
Also, you can try to rewrite contains like this:
Copy code
operator fun <T:String?> contains(pair : Pair<Column<T>, String>) = select { pair.first eq stringParam(pair.second)}.limit(1).any()
... to email in UserEntity
👍 1