laglangyue commented on code in PR #624: URL: https://github.com/apache/pekko-connectors/pull/624#discussion_r1581076680
########## couchbase3/src/main/scala/org/apache/pekko/stream/connectors/couchbase3/scaladsl/CouchbaseSource.scala: ########## @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pekko.stream.connectors.couchbase3.scaladsl + +import com.couchbase.client.java.{ AsyncCollection, AsyncScope } +import com.couchbase.client.java.analytics.{ AnalyticsOptions, AnalyticsResult } +import com.couchbase.client.java.codec.TypeRef +import com.couchbase.client.java.json.JsonObject +import com.couchbase.client.java.kv._ +import com.couchbase.client.java.manager.query.{ GetAllQueryIndexesOptions, QueryIndex } +import com.couchbase.client.java.query.{ QueryOptions, QueryResult } +import org.apache.pekko.NotUsed +import org.apache.pekko.stream.scaladsl.Source + +object CouchbaseSource { + + /** + * get a document by id from Couchbase collection + * @param id document id + * @param options reference to Couchbase options doc + */ + def get(id: String, options: GetOptions = GetOptions.getOptions)( + implicit asyncCollection: AsyncCollection): Source[GetResult, NotUsed] = + Source.completionStage(asyncCollection.get(id, options)) + + /** + * reference to [[CouchbaseSource.get]] deserialize to Couchbase JsonObject + */ + def getJson(id: String, options: GetOptions = GetOptions.getOptions)( + implicit asyncCollection: AsyncCollection): Source[JsonObject, NotUsed] = + get(id, options).map(_.contentAsObject()) + + /** + * reference to [[CouchbaseSource.get]],deserialize to class + * If you add DefaultScalaModule to jackson of couchbase, it could deserialize to scala class + */ + def getObject[T](id: String, target: Class[T], options: GetOptions = GetOptions.getOptions)( + implicit asyncCollection: AsyncCollection): Source[T, NotUsed] = + get(id, options).map(_.contentAs(target)) + + /** + * reference to [[CouchbaseSource.getObject]],deserialize to class with Generics + */ + def getType[T](id: String, target: TypeRef[T], options: GetOptions = GetOptions.getOptions)( + implicit asyncCollection: AsyncCollection): Source[T, NotUsed] = { + get(id, options).map(_.contentAs(target)) + } + + /** + * same to Get option, but reads from all replicas on the active node Review Comment: I hope to express that this method is essentially the same as get() -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
