All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.trendyol.stove.testing.e2e.couchbase.ClusterExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1f1ca59
Show newest version
package com.trendyol.stove.testing.e2e.couchbase

import com.couchbase.client.java.ReactiveCluster
import com.couchbase.client.java.json.JsonObject
import com.couchbase.client.java.query.QueryOptions
import com.couchbase.client.java.query.QueryProfile
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.reactive.asFlow

object ClusterExtensions {

    fun QueryOptions.withParams(vararg params: Pair): QueryOptions {
        val jObject = JsonObject.create()
        params.forEach { jObject.put(it.first, it.second) }
        this.parameters(jObject)
        return this
    }

    suspend inline fun  ReactiveCluster.executeQueryAs(
        query: String,
        queryOptionsConfigurer: (QueryOptions) -> Unit = {}
    ): List {
        val options = createDefaultQueryOptions()
        queryOptionsConfigurer(options)
        return this.query(query, options).flatMapMany { it.rowsAs(T::class.java) }.asFlow().toList()
    }

    fun createDefaultQueryOptions(): QueryOptions {
        return QueryOptions.queryOptions().profile(QueryProfile.OFF).readonly(true)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy