ScalikeJDBC Composable DSL by Free Monad
def createProgrammer[F[_]](name: Name, skillIds: List[SkillId])(implicit S: ScalikeJDBC[F], M: Applicative[Free[F, ?]]) = {
import S._
for {
id <- generateKey(insert.into(Programmer).namedValues(pc.name -> name))
skills <- list(select.from(Skill as s).where.in(s.id, skillIds))(Skill(s))
_ <- skills.traverse[Free[F, ?], Boolean](s => execute(insert.into(ProgrammerSkill).namedValues(sc.programmerId -> id, sc.skillId -> s.id)))
} yield Programmer(id, name, skills)
}
val newProgrammer = DB.localTx {
Interpreter.transaction.run(createProgrammer("Alice", List(2, 3)))
}