Created
June 5, 2012 19:13
-
-
Save LeifWarner/2877089 to your computer and use it in GitHub Desktop.
JDBC query using scala-arm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sql[T](q: String)(f: ResultSet => T): Either[List[Throwable], T] = (for { | |
connection <- managed( datasource.getConnection ) | |
statement <- managed( connection.createStatement ) | |
resultSet <- managed( statement.executeQuery(q) ) | |
} yield resultSet).acquireFor(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without so many ()....
And with delimited continuations:
The
r
function is a bit odd, but helps reduce some boilerplate. The code compiles to the same as before, it just looks "flat" if you prefer. The downside to delimited continuations is the failure to infer the type to thereflect
call. That's why you have a bit more work here, but it's not bad.