title: Get or Insert within a Transaction on Doobie in Scala
body: <p>I'm reading through the Doobie documentation and trying to do a simple get or create within a transaction. I get an option off the first query and attempt to do a <code>getOrElse</code> and run an insert within the else, however I keep getting a <code>value map is not a member of Any</code> within the <code>getOrElse</code> call. What's the correct way to either get an existing or create a new row in <code>instances</code> and return that result in a transaction? </p>
  
  <pre><code>import doobie._
  import doobie.implicits._
  import cats._
  import cats.effect._
  import cats.implicits._
  import org.joda.time.DateTime
  
  import scala.concurrent.ExecutionContext
  
  case class Instance(id : Int, hostname : String)
  
  case class User(id : Int, instanceId: Int, username : String, email : String, created : DateTime)
  
  class Database(dbUrl : String, dbUser: String, dbPass: String) {
  
    implicit val cs = IO.contextShift(ExecutionContext.global)
  
    val xa = Transactor.fromDriverManager[IO](
      "org.postgresql.Driver", dbUrl, dbUser, dbPass
    )
  
    def getOrCreateInstance(hostname: String) = for {
      existingInstance &lt;- sql"SELECT id, hostname FROM instances i WHERE i.hostname = $hostname".query[Instance].option
      ensuredInstance &lt;- existingInstance.getOrElse(sql"INSERT INTO instances(hostname) VALUES(?)".update.withGeneratedKeys[Instance]("id", "hostname"))
    } yield ensuredInstance
  
  }
  </code></pre>