
com.couchbase.client.kotlin.samples.ClusterSamples.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-client Show documentation
Show all versions of kotlin-client Show documentation
The official Couchbase Kotlin SDK
/*
* Copyright (c) 2021 Couchbase, Inc.
*
* Licensed 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 com.couchbase.client.kotlin.samples
import com.couchbase.client.core.env.NetworkResolution
import com.couchbase.client.core.retry.FailFastRetryStrategy
import com.couchbase.client.core.service.ServiceType
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.codec.RawJsonTranscoder
import com.couchbase.client.kotlin.env.ClusterEnvironment
import com.couchbase.client.kotlin.env.dsl.TrustSource
import com.couchbase.client.kotlin.kv.Durability
import com.couchbase.client.kotlin.query.execute
import kotlinx.coroutines.runBlocking
import java.nio.file.Paths
import java.util.Optional
import kotlin.time.Duration.Companion.seconds
@Suppress("UNUSED_VARIABLE")
internal fun quickstart() {
// Quickstart
// Assumes you have Couchbase running locally
// and the "travel-sample" sample bucket loaded.
// Connect and open a bucket
val cluster = Cluster.connect("127.0.0.1", "Administrator", "password")
try {
val bucket = cluster.bucket("travel-sample")
val collection = bucket.defaultCollection()
runBlocking {
// Perform a SQL++ query
val queryResult = cluster
.query("select * from `travel-sample` limit 3")
.execute()
queryResult.rows.forEach { println(it) }
println(queryResult.metadata)
// Get a document from the K/V service
val getResult = collection.get("airline_10")
println(getResult)
println(getResult.contentAs
© 2015 - 2025 Weber Informatics LLC | Privacy Policy