Skip to content

Commit 8678981

Browse files
committed
CBBucket: Add getCounter and make counter's delta param default to 0L
1 parent 3b730f3 commit 8678981

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

core/src/main/scala/com/sandinh/couchbase/CBBucket.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import scala.concurrent.duration._
4545
import scala.concurrent.duration.Duration.MinusInf
4646
import scala.reflect.ClassTag
4747
import scala.reflect.runtime.universe.WeakTypeTag
48+
import Implicits.DocNotExistFuture
4849

4950
/** @define CounterDoc though it is common to use Couchbase to store exclusively JSON, Couchbase is actually
5051
* agnostic to what is stored. It is possible to use a document as a 'counter' - e.g. it
@@ -574,7 +575,7 @@ final class CBBucket(val underlying: AsyncBucket, val cluster: AsyncCluster) {
574575
*/
575576
def counter(
576577
id: String,
577-
delta: Long,
578+
delta: Long = 0L,
578579
initial: Option[Long] = None,
579580
durability: Durability = Disabled,
580581
timeout: Duration = MinusInf, // MinusInf will be converted to kvReadTimeout
@@ -592,6 +593,12 @@ final class CBBucket(val underlying: AsyncBucket, val cluster: AsyncCluster) {
592593
)
593594
)
594595

596+
/** convenient method. {{{ = counter(id).map(_.content).recoverNotExist(default) }}} */
597+
def getCounter(id: String, default: Long = 0L)(
598+
implicit ec: ExecutionContext
599+
): Future[Long] =
600+
counter(id).map(_.content).recoverNotExist(default)
601+
595602
/** See doc of the other overload method */
596603
def counter(
597604
id: String,

0 commit comments

Comments
 (0)