I’m trying to make two methods:
def count()(using con: Connection): Long = ???
def count(): Long =
Using.resource(ds.getConnection())(con => count()(using con))
One creates a new java.sql.Connection, the other requires an implicit Connection as part of a transaction.
But this is code will not compile at the callsite, since scalac gives a ‘Ambiguous overload’ error. Is there a reasonable workarround for this?
I’ve tried two other ideas that didn’t work. First, using a default argument:
def count()(using con: Connection = ds.getConnection()): Long = ???
This doesn’t work because there’s no way to know if the Connection should be close()'d when done.
Then, I tried using scala.util.NotGiven, but that gives the same Ambiguous overload error.