title: How to use transaction in slick
body: <p>I have insert method like this (weight is index)</p>
  
  <pre><code>implicit def run[A](action: DBIOAction[A, NoStream, _ &lt;: slick.dbio.Effect]): Future[A] = {
      db.run(action)
    }
  
  def insert(newCategory: CategoryExtractor): Future[Either[String, CategoryResponse]] = {
          category.map(_.weight).max.result.flatMap {
            case Some(weight) =&gt;
              val temp = newCategory.copy(weight = weight+1)
              (category += temp).andThen(DBIO.successful(Right(toCategoryExtractor(temp))))
            case None =&gt;
              val temp = newCategory.copy(weight = 1)
              (category += temp).andThen(DBIO.successful(Right(toCategoryExtractor(temp))))
          }
    }
  </code></pre>
  
  <p>and I call it 2 time</p>
  
  <pre><code>insert(CategoryExtractor("1", "name", "scala every where", 0, 0, 0, None)) onComplete {
      case Success(data) =&gt; println(data)
    }
  
  insert(CategoryExtractor("2", "name", "haskell every where", 0, 0, 0, None)) onComplete {
      case Success(data) =&gt; println(data)
    }
  </code></pre>
  
  <p>and it return exception(Unique index).</p>
  
  <p>How to fix this and I don't use for-comprehension or insert in first onComplete. Just call it 2 time.</p>
  
  <p>Thank you.</p>