traitWithCaoKey1[T, A, U, D <: Document[U]] extends CaoTrait[T, A, U, D]
This trait has a similar interface as CaoBase but:
+ Has an additional abstract method def key(a: A): String
+ When interact (get/set/update/..) with couchbase server, instead of
So, instead of working with docId: String directly,
we can create a Cao (Couchbase Access Object) for own type T (ex UserCao for T=case class User(uid: Long,...))
, and in UserCao, we define def key(uid: Long) = s"my_prefix$id"
, then using set/get/.. with uid: Long instead of docId: String
To able to do that, we need implement this class' abstract methods: reads(u: U): T and writes(t: T): U
T
type that will be encoded before upsert using writes(t: T): U,
and decoded after get using reads(u: U): T
U
the Document's content type, ex JsValue, primitive types,..
See classes that implement com.couchbase.client.java.document.Document for all available type
(of course you can implement your own)
This trait has a similar interface as CaoBase but: + Has an additional abstract method
def key(a: A): String
+ When interact (get/set/update/..) with couchbase server, instead ofas in CaoBase, we can:
So, instead of working with
docId: String
directly, we can create a Cao (Couchbase Access Object) for own type T (ex UserCao for T=case class User(uid: Long,...)
) , and inUserCao
, we definedef key(uid: Long) = s"my_prefix$id"
, then using set/get/.. withuid: Long
instead ofdocId: String
To able to do that, we need implement this class' abstract methods:reads(u: U): T
andwrites(t: T): U
type that will be encoded before upsert using
writes(t: T): U
, and decoded after get usingreads(u: U): T
the Document's content type, ex JsValue, primitive types,.. See classes that implement
com.couchbase.client.java.document.Document
for all available type (of course you can implement your own)the Document type