Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #76 from gnieh/scala/2.12
Browse files Browse the repository at this point in the history
Add support for scala 2.12
  • Loading branch information
satabin authored Nov 24, 2016
2 parents c49ea28 + fbe2bc7 commit c090636
Show file tree
Hide file tree
Showing 30 changed files with 136 additions and 190 deletions.
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ lazy val globalSettings = Seq(
licenses += ("The Apache Software License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
homepage := Some(url("https://github.com/gnieh/sohva")),
version := "2.0.2-SNAPSHOT",
scalaVersion := "2.11.8",
scalaVersion := "2.12.0",
crossScalaVersions := Seq("2.12.0", "2.11.8"),
libraryDependencies ++= globalDependencies,
parallelExecution := false,
fork in Test := true,
Expand All @@ -27,8 +28,8 @@ lazy val scalariform = scalariformSettings ++ Seq(

lazy val globalDependencies = Seq(
"org.scalatest" %% "scalatest" % "3.0.0" % "test",
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.10",
"org.gnieh" %% "diffson" % "2.0.2",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.0.0",
"org.gnieh" %% "diffson-spray-json" % "2.1.0",
"io.spray" %% "spray-json" % "1.3.2",
"org.slf4j" % "slf4j-api" % "1.7.21"
)
Expand All @@ -37,11 +38,11 @@ lazy val publishSettings = Seq(
publishMavenStyle := true,
publishArtifact in Test := false,
// The Nexus repo we're publishing to.
publishTo <<= version { (v: String) =>
publishTo := (version { (v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
}).value,
pomIncludeRepository := { x => false },
pomExtra := (
<scm>
Expand Down Expand Up @@ -74,7 +75,7 @@ lazy val sohva = project.in(file("."))
.settings(globalSettings: _*)
.settings(publishSettings: _*)
.settings(osgiSettings: _*)
.settings(scalariformSettings: _*)
.settings(scalariform: _*)
.settings (
name := "sohva",
description := "Couchdb client library",
Expand All @@ -99,4 +100,4 @@ lazy val json = project.in(file("sohva-json"))
.settings(globalSettings: _*)
.settings(
libraryDependencies ++= globalDependencies,
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _))
libraryDependencies += scalaVersion("org.scala-lang" % "scala-reflect" % _).value)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.7
sbt.version=0.13.13
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.2.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.1")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.1.0")
3 changes: 1 addition & 2 deletions src/main/scala/gnieh/sohva/BasicSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import scala.concurrent.Future
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.BasicHttpCredentials

/**
* An instance of a Couch session that allows the user to perform authenticated
/** An instance of a Couch session that allows the user to perform authenticated
* operations using HTTP basic authentication.
*
* @author Lucas Satabin
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/gnieh/sohva/CList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import akka.stream.ActorMaterializer
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling._

/**
* A list that can be queried for a given view.
/** A list that can be queried for a given view.
*
* @author Lucas Satabin
*/
Expand Down
14 changes: 6 additions & 8 deletions src/main/scala/gnieh/sohva/ChangeStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import scala.concurrent.duration.Duration

import java.util.concurrent.atomic.AtomicLong

/**
* A stream that represents a connection to the `_changes` stream of a database.
/** A stream that represents a connection to the `_changes` stream of a database.
*
* @author Lucas Satabin
*/
Expand Down Expand Up @@ -81,8 +80,8 @@ class ChangeStream(database: Database) {
limit.map(n => "limit" -> n.toString),
since.map {
case Left("now") => "since" -> "now"
case Left(s) => throw new SohvaException(f"Unsupported `since` value $s")
case Right(s) => "since" -> CompactPrinter(s)
case Left(s) => throw new SohvaException(f"Unsupported `since` value $s")
case Right(s) => "since" -> CompactPrinter(s)
},
style.map(s => "style" -> s),
view.map(v => "view" -> v)).flatten
Expand All @@ -98,8 +97,7 @@ class ChangeStream(database: Database) {

}

/**
* Returns a continuous stream representing the changes in the database. Each change produces an element in the stream.
/** Returns a continuous stream representing the changes in the database. Each change produces an element in the stream.
* The returned stream can be cancelled using the kill switch returned by materializing it.
* E.g. if you want to log the changes to the console and shut it down after a while, you can write
* {{{
Expand Down Expand Up @@ -135,8 +133,8 @@ class ChangeStream(database: Database) {
limit.map(n => "limit" -> n.toString),
since.map {
case Left("now") => "since" -> "now"
case Left(s) => throw new SohvaException(f"Unsupported `since` value $s")
case Right(s) => "since" -> CompactPrinter(s)
case Left(s) => throw new SohvaException(f"Unsupported `since` value $s")
case Right(s) => "since" -> CompactPrinter(s)
},
style.map(s => "style" -> s),
view.map(v => "view" -> v)).flatten
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/gnieh/sohva/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import scala.util.Properties

import java.util.Date

/**
* The configuration object of a couchdb instance
/** The configuration object of a couchdb instance
*
* @author Lucas Satabin
*/
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/gnieh/sohva/CouchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import akka.stream.{
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._

/**
* A CouchDB instance.
/** A CouchDB instance.
* Allows users to access the different databases and instance information.
* This is the key class to start with when one wants to work with couchdb.
* Through this one you will get access to the sessions and anonymous access
Expand Down
17 changes: 6 additions & 11 deletions src/main/scala/gnieh/sohva/CouchDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import akka.util.ByteString

import spray.json._

/**
* A CouchDB instance.
/** A CouchDB instance.
* Allows users to access the different databases and information.
* This is the key class to start with when one wants to work with couchdb.
* Through this one you will get access to the databases.
Expand Down Expand Up @@ -114,8 +113,7 @@ abstract class CouchDB {
.viaMat(KillSwitches.single)(Keep.right)
}

/**
* Returns the list of nodes known by this node and the clusters.
/** Returns the list of nodes known by this node and the clusters.
*
* @group CouchDB2
*/
Expand Down Expand Up @@ -164,8 +162,7 @@ abstract class CouchDB {
def _config(section: String): Future[Map[String, String]] =
config(section)

/**
* Returns the configuration section identified by its name
/** Returns the configuration section identified by its name
* (an empty map is returned if the section does not exist)
*/
def config(section: String): Future[Map[String, String]] =
Expand All @@ -178,8 +175,7 @@ abstract class CouchDB {
def _config(section: String, key: String): Future[Option[String]] =
config(section, key)

/**
* Returns the configuration value
/** Returns the configuration value
* Returns `None` if the value does not exist
*/
def config(section: String, key: String): Future[Option[String]] =
Expand All @@ -188,8 +184,7 @@ abstract class CouchDB {
f"Failed to fetch config for $section with key `$key' from $uri"
) yield section.get(key)

/**
* Saves the given key/value association in the specified section
/** Saves the given key/value association in the specified section
* The section and/or the key is created if it does not exist
*/
def saveConfigValue(section: String, key: String, value: String): Future[Boolean] =
Expand Down Expand Up @@ -252,7 +247,7 @@ abstract class CouchDB {
private def handleOptionalCouchResponse(response: HttpResponse): Future[Option[JsValue]] =
handleCouchResponse(response).map(Some(_)).recoverWith {
case CouchException(404, _) => Future.successful(None)
case err => Future.failed(err)
case err => Future.failed(err)
}

@inline
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/gnieh/sohva/CouchException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object CouchException {

def unapply(exn: Throwable): Option[(Int, Option[ErrorResult])] = exn match {
case exn: CouchException => Some(exn.status -> exn.detail)
case _ => None
case _ => None
}

}
Expand All @@ -39,7 +39,7 @@ object ConflictException {

def unapply(exn: Throwable): Option[Option[ErrorResult]] = exn match {
case CouchException(409, detail) => Some(detail)
case _ => None
case _ => None
}

}
5 changes: 4 additions & 1 deletion src/main/scala/gnieh/sohva/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ class Database private[sohva] (
for {
res <- builtInView("_all_docs").query[String, Map[String, String], JsObject](keys = ids) withFailureMessage
f"Failed to fetch document revisions by IDs $ids from $uri"
} yield res.rows.map { case Row(Some(id), _, value, _) => (id, value("rev")) }
} yield res.rows.flatMap {
case Row(Some(id), _, value, _) => Some(id -> value("rev"))
case Row(None, _, _, _) => None
}

/**
* Finds documents using the declarative mango query syntax. See [[sohva.mango]] for details.
Expand Down
38 changes: 13 additions & 25 deletions src/main/scala/gnieh/sohva/Design.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import spray.json._

import akka.http.scaladsl.model._

/**
* A design gives access to the different views.
/** A design gives access to the different views.
* Use this class to get or create new views.
*
* @author Lucas Satabin
Expand All @@ -37,17 +36,15 @@ class Design(val db: Database,

protected[sohva] val uri = db.uri / "_design" / name.trim

/**
* Check if the design exists.
/** Check if the design exists.
*
* @return true if it does, false otherwise
*/
def exists: Future[Boolean] =
for (h <- db.couch.rawHttp(HttpRequest(HttpMethods.HEAD, uri = uri)))
yield h.status == StatusCodes.OK

/**
* Create an empty design document if none exists.
/** Create an empty design document if none exists.
* Raises an exception if the design already exists.
*
* @return the design document if created..
Expand All @@ -59,8 +56,7 @@ class Design(val db: Database,
else db.saveDoc(DesignDoc("_design/" + name, language, Map(), None, Map(), Map(), Map(), Map(), Nil))
} yield cr

/**
* Returns the design document from the couchdb instance.
/** Returns the design document from the couchdb instance.
* Returns `None` if the design document does not exist.
*/
def getDesignDocument: Future[Option[DesignDoc]] =
Expand All @@ -73,8 +69,7 @@ class Design(val db: Database,
def delete: Future[Boolean] =
db.deleteDoc("_design/" + name.trim)

/**
* Creates or updates the view in this design
/** Creates or updates the view in this design
* with the given name, map function and reduce function.
* If the design does not exist yet, it is created.
*/
Expand All @@ -83,8 +78,7 @@ class Design(val db: Database,
reduceFun: Option[String] = None): Future[Unit] =
saveView(viewName, ViewDoc(mapFun, reduceFun))

/**
* Creates or updates the view in this design with the given name.
/** Creates or updates the view in this design with the given name.
* If the design does not exist yet, it is created.
*/
def saveView(viewName: String, view: ViewDoc): Future[Unit] =
Expand Down Expand Up @@ -121,8 +115,7 @@ class Design(val db: Database,
def view(viewName: String): View =
new View(this.name, db, viewName)

/**
* Creates or update the show function in this design with the given name.
/** Creates or update the show function in this design with the given name.
* If the design does not exist yet, it is created.
*/
def saveShow(showName: String, showFun: String): Future[Unit] =
Expand Down Expand Up @@ -159,8 +152,7 @@ class Design(val db: Database,
def show(showName: String): Show =
new Show(this.name, db, showName)

/**
* Creates or update the update function in this design with the given name.
/** Creates or update the update function in this design with the given name.
* If the design does not exist yet, it is created.
*/
def saveList(listName: String, listFun: String): Future[Unit] =
Expand Down Expand Up @@ -197,8 +189,7 @@ class Design(val db: Database,
def list(listName: String): CList =
new CList(this.name, db, listName)

/**
* Creates or update the update function in this design with the given name.
/** Creates or update the update function in this design with the given name.
* If the design does not exist yet, it is created.
*/
def saveUpdate(updateName: String, updateFun: String): Future[Unit] =
Expand Down Expand Up @@ -235,8 +226,7 @@ class Design(val db: Database,
def update(updateName: String): Update =
new Update(this.name, db, updateName)

/**
* Creates or updates the document validation function.
/** Creates or updates the document validation function.
* If the design does not exist yet, it is created.
*/
def saveValidateFunction(validateFun: String): Future[Unit] =
Expand Down Expand Up @@ -270,8 +260,7 @@ class Design(val db: Database,
case None => Future.failed(new SohvaException("Unable to delete validate function for unknown design: " + name))
}

/**
* Creates or updates a filter function.
/** Creates or updates a filter function.
* If the design does not exist yet, it is created.
*/
def saveFilter(name: String, filterFun: String): Future[Unit] =
Expand Down Expand Up @@ -306,8 +295,7 @@ class Design(val db: Database,
Future.failed(new SohvaException("Unable to delete filter " + filterName + " for unknown design " + name))
}

/**
* Creates or updates the list of rewrite rules.
/** Creates or updates the list of rewrite rules.
* If the design does not exist yet, it is created.
*/
def saveRewriteRules(rules: List[RewriteRule]): Future[Unit] =
Expand All @@ -331,7 +319,7 @@ class Design(val db: Database,
for (design <- getDesignDocument)
yield design match {
case Some(d) => d.rewrites
case None => Nil
case None => Nil
}

/** Requests compaction of this design. */
Expand Down
8 changes: 3 additions & 5 deletions src/main/scala/gnieh/sohva/DocumentOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ abstract class DocumentOps {
for (raw <- optHttp(HttpRequest(uri = uri / id <<? revision.flatMap(r => if (r.nonEmpty) Some("rev" -> r) else None))).withFailureMessage(f"Failed to fetch document by ID $id and revision $revision"))
yield raw.map(_.convertTo[T])

/**
* Creates or updates the given object as a document into this database
/** Creates or updates the given object as a document into this database
* The given object must have an `_id` and an optional `_rev` fields
* to conform to the couchdb document structure.
* The saved revision is returned. If something went wrong, an exception is raised
Expand Down Expand Up @@ -103,7 +102,7 @@ abstract class DocumentOps {
resolved = strategy(base, last, current)
res <- resolved match {
case Some(resolved) => resolver(credit - 1, docId, lastRev, resolved)
case None => Future.failed(exn)
case None => Future.failed(exn)
}
} yield res
} withFailureMessage f"Unable to resolve document with ID $docId at revision $baseRev"
Expand All @@ -123,8 +122,7 @@ abstract class DocumentOps {
Future.failed(new SohvaException("Document $id could not be saved"))
}

/**
* Deletes the document from the database.
/** Deletes the document from the database.
* The document will only be deleted if the caller provided the last revision
*/
def deleteDoc[T: CouchFormat](doc: T): Future[Boolean] = {
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/gnieh/sohva/OAuthSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import scala.concurrent.Future

import akka.http.scaladsl.model._

/**
* An instance of a Couch session that allows the user to perform authenticated
/** An instance of a Couch session that allows the user to perform authenticated
* operations using OAuth.
*
* @author Lucas Satabin
Expand Down
Loading

0 comments on commit c090636

Please sign in to comment.