Skip to content

Instantly share code, notes, and snippets.

View oharaandrew314's full-sized avatar

Andrew O'Hara oharaandrew314

View GitHub Profile
import org.http4k.connect.amazon.dynamodb.FakeDynamoDb
import org.http4k.connect.amazon.dynamodb.mapper.tableMapper
import org.http4k.connect.amazon.dynamodb.model.TableName
import java.util.UUID
private fun testTable(tableName: TableName = TableName.of("cats")) = FakeDynamoDb()
.client()
.tableMapper<Cat, UUID, Unit>(tableName, Http4kDynamoCatsRepo.Schema.primaryIndex)
.also { it.createTable(Http4kDynamoCatsRepo.Schema.ownerIndex) }
import org.http4k.connect.amazon.dynamodb.mapper.DynamoDbTableMapper
import org.http4k.connect.amazon.dynamodb.mapper.DynamoDbTableMapperSchema
import org.http4k.connect.amazon.dynamodb.model.Attribute
import org.http4k.connect.amazon.dynamodb.model.IndexName
import java.util.UUID
class Http4kDynamoCatsRepo(private val table: DynamoDbTableMapper<Cat, UUID, Unit>): CatsRepo {
object Schema {
private val idAttr = Attribute.uuid().required("id")
import io.andrewohara.awsmock.dynamodb.MockDynamoDbV2
import io.andrewohara.dynamokt.DataClassTableSchema
import io.andrewohara.dynamokt.createTableWithIndices
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient
private fun testTable() = DynamoDbEnhancedClient.builder()
.dynamoDbClient(MockDynamoDbV2())
.build()
.table("cats", DataClassTableSchema(DynamoCat::class))
.also { it.createTableWithIndices() }
import io.andrewohara.dynamokt.DynamoKtPartitionKey
import io.andrewohara.dynamokt.DynamoKtSecondaryPartitionKey
import io.andrewohara.dynamokt.DynamoKtSecondarySortKey
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable
import software.amazon.awssdk.enhanced.dynamodb.Key
import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional
import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest
import java.util.UUID
class V2DynamoCatsRepo(private val mapper: DynamoDbTable<DynamoCat>): CatsRepo {
import org.h2.jdbcx.JdbcDataSource
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.UUID
import javax.sql.DataSource
private fun testDb(): Database {
val dataSource: DataSource = JdbcDataSource().apply {
setURL("jdbc:h2:mem:${UUID.randomUUID()};MODE=MySQL;DB_CLOSE_DELAY=-1")
import org.jetbrains.exposed.dao.id.UUIDTable
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.UUID
import org.h2.jdbcx.JdbcDataSource
import java.util.UUID
import javax.sql.DataSource
private fun testDb(): DataSource {
val dataSource = JdbcDataSource().apply {
setURL("jdbc:h2:mem:${UUID.randomUUID()};MODE=MySQL;DB_CLOSE_DELAY=-1")
this.user = "sa"
this.password = ""
}
import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import java.util.UUID
private val ownerId = UUID.randomUUID()
private val kratos = Cat(
id = UUID.randomUUID(),
import java.sql.ResultSet
import java.util.UUID
import javax.sql.DataSource
class JdbcCatsRepo(private val datasource: DataSource): CatsRepo {
override fun plusAssign(cat: Cat) {
datasource.connection.use { conn ->
conn.prepareStatement("INSERT INTO cats (id, ownerId, name) VALUES (?, ?, ?)").use { stmt ->
stmt.setString(1, cat.id.toString())
import java.util.UUID
data class Cat(
val id: UUID,
val name: String,
val ownerId: UUID
)
interface CatsRepo {
operator fun get(id: UUID): Cat?