commonMain.aws.sdk.kotlin.hll.dynamodbmapper.operations.ItemSourceOperations.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamodb-mapper-jvm Show documentation
Show all versions of dynamodb-mapper-jvm Show documentation
High level DynamoDbMapper client
// Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT!
package aws.sdk.kotlin.hll.dynamodbmapper.operations
import aws.sdk.kotlin.hll.dynamodbmapper.annotations.ManualPagination
import aws.smithy.kotlin.runtime.ExperimentalApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.transform
import kotlin.jvm.JvmName
/**
* Provides access to operations on a particular itemSource, which will invoke low-level
* operations after mapping objects to items and vice versa
* @param T The type of objects which will be read from and/or written to this itemSource
*/
@ExperimentalApi
public interface ItemSourceOperations {
@ManualPagination(paginatedEquivalent = "queryPaginated")
public suspend fun query(request: QueryRequest): QueryResponse
@ManualPagination(paginatedEquivalent = "scanPaginated")
public suspend fun scan(request: ScanRequest): ScanResponse
}
@ManualPagination(paginatedEquivalent = "queryPaginated")
public suspend inline fun ItemSourceOperations.query(crossinline block: QueryRequestBuilder.() -> Unit): QueryResponse =
query(QueryRequestBuilder().apply(block).build())
@ManualPagination(paginatedEquivalent = "scanPaginated")
public suspend inline fun ItemSourceOperations.scan(crossinline block: ScanRequestBuilder.() -> Unit): ScanResponse =
scan(ScanRequestBuilder().apply(block).build())
@ExperimentalApi
public fun ItemSourceOperations.queryPaginated(initialRequest: QueryRequest): Flow> = flow {
var cursor = initialRequest.exclusiveStartKey
var hasNextPage = true
while (hasNextPage) {
val req = initialRequest.copy { exclusiveStartKey = cursor }
@OptIn(ManualPagination::class)
val res = [email protected](req)
cursor = res.lastEvaluatedKey
hasNextPage = cursor != null
emit(res)
}
}
@ExperimentalApi
public inline fun ItemSourceOperations.queryPaginated(crossinline block: QueryRequestBuilder.() -> Unit): Flow> =
queryPaginated(QueryRequestBuilder().apply(block).build())
@ExperimentalApi
public fun ItemSourceOperations.scanPaginated(initialRequest: ScanRequest): Flow> = flow {
var cursor = initialRequest.exclusiveStartKey
var hasNextPage = true
while (hasNextPage) {
val req = initialRequest.copy { exclusiveStartKey = cursor }
@OptIn(ManualPagination::class)
val res = [email protected](req)
cursor = res.lastEvaluatedKey
hasNextPage = cursor != null
emit(res)
}
}
@ExperimentalApi
public inline fun ItemSourceOperations.scanPaginated(crossinline block: ScanRequestBuilder.() -> Unit): Flow> =
scanPaginated(ScanRequestBuilder().apply(block).build())
@ExperimentalApi
@JvmName("queryItems")
public fun Flow>.items(): Flow =
transform { page ->
page.items?.forEach { item ->
emit(item)
}
}
@ExperimentalApi
@JvmName("scanItems")
public fun Flow>.items(): Flow =
transform { page ->
page.items?.forEach { item ->
emit(item)
}
}