This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
data class Cat( | |
val id: UUID, | |
val name: String, | |
val ownerId: UUID | |
) | |
interface CatsRepo { | |
operator fun get(id: UUID): Cat? |
NewerOlder