commonMain.aws.sdk.kotlin.hll.dynamodbmapper.operations.Scan.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.expressions.BooleanExpr
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.Filter
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.FilterImpl
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.ParameterizingExpressionVisitor
import aws.sdk.kotlin.hll.dynamodbmapper.internal.withWrappedClient
import aws.sdk.kotlin.hll.dynamodbmapper.items.ItemSchema
import aws.sdk.kotlin.hll.dynamodbmapper.model.IndexSpec
import aws.sdk.kotlin.hll.dynamodbmapper.model.TableSpec
import aws.sdk.kotlin.hll.dynamodbmapper.model.toItem
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.HReqContextImpl
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.MapperContextImpl
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.Operation
import aws.sdk.kotlin.services.dynamodb.model.ConsumedCapacity
import aws.sdk.kotlin.services.dynamodb.model.ReturnConsumedCapacity
import aws.sdk.kotlin.services.dynamodb.model.Select
import aws.smithy.kotlin.runtime.ExperimentalApi
import kotlin.collections.List
import aws.sdk.kotlin.services.dynamodb.model.ScanRequest as LowLevelScanRequest
import aws.sdk.kotlin.services.dynamodb.model.ScanResponse as LowLevelScanResponse
@ExperimentalApi
public interface ScanRequest {
@ExperimentalApi
public companion object { }
public val consistentRead: Boolean?
public val exclusiveStartKey: T?
public val filter: BooleanExpr?
public val limit: Int?
public val returnConsumedCapacity: ReturnConsumedCapacity?
public val segment: Int?
public val select: Select?
public val totalSegments: Int?
}
private data class ScanRequestImpl(
override val consistentRead: Boolean?,
override val exclusiveStartKey: T?,
override val filter: BooleanExpr?,
override val limit: Int?,
override val returnConsumedCapacity: ReturnConsumedCapacity?,
override val segment: Int?,
override val select: Select?,
override val totalSegments: Int?,
): ScanRequest
/**
* A DSL-style builder for instances of [ScanRequest]
*/
@ExperimentalApi
public class ScanRequestBuilder {
public var consistentRead: Boolean? = null
public var exclusiveStartKey: T? = null
public var filter: BooleanExpr? = null
public fun filter(block: Filter.() -> BooleanExpr?) {
filter = FilterImpl.run(block)
}
public var limit: Int? = null
public var returnConsumedCapacity: ReturnConsumedCapacity? = null
public var segment: Int? = null
public var select: Select? = null
public var totalSegments: Int? = null
public fun build(): ScanRequest {
val consistentRead = consistentRead
val exclusiveStartKey = exclusiveStartKey
val filter = filter
val limit = limit
val returnConsumedCapacity = returnConsumedCapacity
val segment = segment
val select = select
val totalSegments = totalSegments
return ScanRequestImpl(
consistentRead,
exclusiveStartKey,
filter,
limit,
returnConsumedCapacity,
segment,
select,
totalSegments,
)
}
}
@ExperimentalApi
public fun ScanRequest.toBuilder(): ScanRequestBuilder = ScanRequestBuilder().apply {
consistentRead = [email protected]
exclusiveStartKey = [email protected]
filter = [email protected]
limit = [email protected]
returnConsumedCapacity = [email protected]
segment = [email protected]
select = [email protected]
totalSegments = [email protected]
}
@ExperimentalApi
public fun ScanRequest.copy(block: ScanRequestBuilder.() -> Unit): ScanRequest =
toBuilder().apply(block).build()
@ExperimentalApi
public fun ScanRequest(block: ScanRequestBuilder.() -> Unit): ScanRequest =
ScanRequestBuilder().apply(block).build()
private fun ScanRequest.convert(
indexName: String?,
tableName: String?,
schema: ItemSchema,
) = LowLevelScanRequest {
consistentRead = [email protected]
limit = [email protected]
returnConsumedCapacity = [email protected]
segment = [email protected]
select = [email protected]
totalSegments = [email protected]
[email protected]?.let { exclusiveStartKey = schema.converter.convertTo(it) }
this.indexName = indexName
this.tableName = tableName
val expressionVisitor = ParameterizingExpressionVisitor()
filterExpression = [email protected]?.accept(expressionVisitor)
expressionAttributeNames = expressionVisitor.expressionAttributeNames()
expressionAttributeValues = expressionVisitor.expressionAttributeValues()
}
@ExperimentalApi
public interface ScanResponse {
@ExperimentalApi
public companion object { }
public val consumedCapacity: ConsumedCapacity?
public val count: Int
public val items: List?
public val lastEvaluatedKey: T?
public val scannedCount: Int
}
private data class ScanResponseImpl(
override val consumedCapacity: ConsumedCapacity?,
override val count: Int,
override val items: List?,
override val lastEvaluatedKey: T?,
override val scannedCount: Int,
): ScanResponse
/**
* A DSL-style builder for instances of [ScanResponse]
*/
@ExperimentalApi
public class ScanResponseBuilder {
public var consumedCapacity: ConsumedCapacity? = null
public var count: Int? = null
public var items: List? = null
public var lastEvaluatedKey: T? = null
public var scannedCount: Int? = null
public fun build(): ScanResponse {
val consumedCapacity = consumedCapacity
val count = requireNotNull(count) { "Missing value for count" }
val items = items
val lastEvaluatedKey = lastEvaluatedKey
val scannedCount = requireNotNull(scannedCount) { "Missing value for scannedCount" }
return ScanResponseImpl(
consumedCapacity,
count,
items,
lastEvaluatedKey,
scannedCount,
)
}
}
@ExperimentalApi
public fun ScanResponse.toBuilder(): ScanResponseBuilder = ScanResponseBuilder().apply {
consumedCapacity = [email protected]
count = [email protected]
items = [email protected]
lastEvaluatedKey = [email protected]
scannedCount = [email protected]
}
@ExperimentalApi
public fun ScanResponse.copy(block: ScanResponseBuilder.() -> Unit): ScanResponse =
toBuilder().apply(block).build()
@ExperimentalApi
public fun ScanResponse(block: ScanResponseBuilder.() -> Unit): ScanResponse =
ScanResponseBuilder().apply(block).build()
private fun LowLevelScanResponse.convert(schema: ItemSchema) = ScanResponse {
consumedCapacity = [email protected]
count = [email protected]
scannedCount = [email protected]
lastEvaluatedKey = [email protected]?.toItem()?.let(schema.converter::convertFrom)
items = [email protected]?.map { schema.converter.convertFrom(it.toItem()) }
}
internal fun scanOperation(spec: IndexSpec) = Operation(
initialize = { highLevelReq: ScanRequest -> HReqContextImpl(highLevelReq, spec.schema, MapperContextImpl(spec, "Scan")) },
serialize = { highLevelReq, schema -> highLevelReq.convert(spec.indexName, spec.tableName, schema) },
lowLevelInvoke = { lowLevelReq ->
spec.mapper.client.withWrappedClient { client ->
client.scan(lowLevelReq)
}
},
deserialize = LowLevelScanResponse::convert,
interceptors = spec.mapper.config.interceptors,
)
internal fun scanOperation(spec: TableSpec) = Operation(
initialize = { highLevelReq: ScanRequest -> HReqContextImpl(highLevelReq, spec.schema, MapperContextImpl(spec, "Scan")) },
serialize = { highLevelReq, schema -> highLevelReq.convert(indexName = null, spec.tableName, schema) },
lowLevelInvoke = { lowLevelReq ->
spec.mapper.client.withWrappedClient { client ->
client.scan(lowLevelReq)
}
},
deserialize = LowLevelScanResponse::convert,
interceptors = spec.mapper.config.interceptors,
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy