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

commonMain.aws.sdk.kotlin.hll.dynamodbmapper.operations.TableOperations.kt Maven / Gradle / Ivy

There is a newer version: 1.3.73-beta
Show newest version
// 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.sdk.kotlin.hll.dynamodbmapper.model.TableSpec
import aws.smithy.kotlin.runtime.ExperimentalApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

/**
 * Provides access to operations on a particular table, 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 table
 */
@ExperimentalApi
public interface TableOperations : ItemSourceOperations {
    public suspend fun deleteItem(request: DeleteItemRequest): DeleteItemResponse
    public suspend fun getItem(request: GetItemRequest): GetItemResponse
    public suspend fun putItem(request: PutItemRequest): PutItemResponse

    @ManualPagination(paginatedEquivalent = "queryPaginated")
    public override suspend fun query(request: QueryRequest): QueryResponse

    @ManualPagination(paginatedEquivalent = "scanPaginated")
    public override suspend fun scan(request: ScanRequest): ScanResponse
}

public suspend inline fun  TableOperations.deleteItem(crossinline block: DeleteItemRequestBuilder.() -> Unit): DeleteItemResponse =
    deleteItem(DeleteItemRequestBuilder().apply(block).build())

public suspend inline fun  TableOperations.getItem(crossinline block: GetItemRequestBuilder.() -> Unit): GetItemResponse =
    getItem(GetItemRequestBuilder().apply(block).build())

public suspend inline fun  TableOperations.putItem(crossinline block: PutItemRequestBuilder.() -> Unit): PutItemResponse =
    putItem(PutItemRequestBuilder().apply(block).build())

@ExperimentalApi
public fun  TableOperations.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  TableOperations.queryPaginated(crossinline block: QueryRequestBuilder.() -> Unit): Flow> =
    queryPaginated(QueryRequestBuilder().apply(block).build())

@ExperimentalApi
public fun  TableOperations.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  TableOperations.scanPaginated(crossinline block: ScanRequestBuilder.() -> Unit): Flow> =
    scanPaginated(ScanRequestBuilder().apply(block).build())

internal class TableOperationsImpl(private val spec: TableSpec) : TableOperations {
    override suspend fun deleteItem(request: DeleteItemRequest) = deleteItemOperation(spec).execute(request)
    override suspend fun getItem(request: GetItemRequest) = getItemOperation(spec).execute(request)
    override suspend fun putItem(request: PutItemRequest) = putItemOperation(spec).execute(request)

    @ManualPagination(paginatedEquivalent = "queryPaginated")
    override suspend fun query(request: QueryRequest) = queryOperation(spec).execute(request)

    @ManualPagination(paginatedEquivalent = "scanPaginated")
    override suspend fun scan(request: ScanRequest) = scanOperation(spec).execute(request)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy