All Downloads are FREE. Search and download functionalities are using the official Maven repository.

e.reactive-mongo_2.11.1.0.43-j7p.source-code.WriteResponse.scala Maven / Gradle / Ivy

package acolyte.reactivemongo

import scala.util.Try

import _root_.reactivemongo.bson.BSONDocument
import _root_.reactivemongo.core.protocol.Response

/** Write response factory. */
object WriteResponse {
  /** Creates a response for given `body`. */
  def apply[T](body: ⇒ T)(implicit mkResponse: WriteResponseMaker[T]): PreparedResponse = new PreparedResponse {
    def apply(chanId: Int) = mkResponse(chanId, body)
  }

  /**
   * Named factory for error response.
   *
   * @param message Error message
   */
  def failed(message: String) = apply(message)

  /**
   * Named factory for error response.
   *
   * @param message Error message
   * @param code Error code
   */
  def failed(message: String, code: Int) = apply(message → code)

  /**
   * Factory for successful response.
   *
   * @param count The number of documents affected by last command, 0 if none
   * @param updatedExisting Some existing document has been updated
   */
  def successful(count: Int = 0, updatedExisting: Boolean = false) =
    apply(count → updatedExisting)

  /**
   * Undefined response, returned by handler no supporting
   * a specific write operation that may be handled by others.
   */
  lazy val undefined = apply(None)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy