Johan Basson
10/09/2019, 9:51 AMfun authenticate(username: String, password: String): Either<Error, Token> {
// validation etc ..
val user = getUserByUsername(username)
}
fun getUserByUsername(username: String): Option<User> {
// JDBC Query for user
val rs = con.prepareStatement("SELECT * FROM user .....")
....
val user = mapRowToUser(rs) // etc
return Option.fromNullable(user)
}
My question is do I pass in the connection of database pool as a parameter like so:
fun authenticate(con: Connection, username: String, password: String) ....
fun getUserByUsername(con: Connection, username: String): Option<User> ...
What is best practise when it comes to functional programming?
Also from what I have read and if my undersyanding is correct, this is inpure and normally IO would be used?
fun getUserByUsername(username: String): IO<Option<User>>
Is this correct? Any help appreciated