Skip to content

urosjarc/db-messiah-extra

Repository files navigation

db-messiah-extra

Extra Utils for db-messiah.
Support for kotlinx datetime and serialization.

+15 e2e tests with 100% instruction coverage
readme code snippets are autogenerated and tested



Kotlin lib. for database development

Get started

Specifications

Arhitecture

Documentation

GUI for db analysis, to help you create complex JOIN statements for SQL or db-messiah.



Get started

implementation("com.urosjarc:db-messiah-extra-extra:0.0.2")


Domain

@Serializable
data class MyTable(
    @Contextual
    val pk: UUID = UUID.randomUUID(),
    val instant: kotlinx.datetime.Instant,
    val localDate: kotlinx.datetime.LocalDate,
    val localTime: kotlinx.datetime.LocalTime,
)


DB Serializers

val sqliteSerializer = SqliteSerializer(
    globalSerializers = BasicTS.sqlite + KotlinxTimeTS.sqlite,
    tables = listOf(Table(MyTable::pk)),
)


JSON Serializers

/** JSON */

val json = Json {
    serializersModule = SerializersModule {
        contextual(InstantJS)
        contextual(LocalDateJS)
        contextual(LocalTimeJS)
        contextual(UUIDJS)
    }
}

/** KTOR */

embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
    install(ContentNegotiation) {
        json(Json {
            serializersModule = SerializersModule {
                contextual(InstantJS)
                contextual(LocalDateJS)
                contextual(LocalTimeJS)
                contextual(UUIDJS)
            }
        })
    }
}

/** USAGE */

val dtNow = Clock.System.now().toLocalDateTime(timeZone = TimeZone.UTC)
val myTable = MyTable(
    instant = Clock.System.now(),
    localDate = dtNow.date,
    localTime = dtNow.time
)
val jsonStr = json.encodeToString(myTable)
val obj = json.decodeFromString<MyTable>(jsonStr)
assert(obj == myTable)



Specifications

Class COLUMN Databases db-messiah-extra JSON
Instant DATETIME Sqlite, Mysql, MSSql, Maria, H2, DB2 KotlinxInstantTS. DATETIME InstantJS
Instant TIMESTAMP Derby, Postgres, Oracle KotlinxInstantTS. TIMESTAMP InstantJS
LocalDateTime
LocalDate DATE KotlinxLocalDateTS. DATE LocalDateJS
LocalTime TIME ✅ but Oracle KotlinxTimeTS.TIME LocalDateJS
LocalTime NUMBER(8, 0) Oracle KotlinxTimeTS. NUMBER8 LocalTimeJS
UUID db-messiah db-messiah db-messiah UUIDJS



Arhitecture

src/main/kotlin/com/urosjarc/dbmessiah/extra/
|-- kotlinx
|   |-- InstantJS.kt............| java.time.Instant serializer for kotlinx.serialization
|   |-- LocalDateJS.kt..........| java.time.LocalDate serializer for kotlinx.serialization
|   |-- LocalTimeJS.kt..........| java.time.LocalTime serializer for kotlinx.serialization
|   `-- UUIDJS.kt...............| java.utils.UUID serializer for kotlinx.serialization
`-- serializers
    |-- KotlinxInstantTS.kt.....| kotlinx.datetime.Instant type serializer for db-messiah
    |-- KotlinxLocalDateTS.kt...| kotlinx.datetime.LocalDate type serializer for db-messiah
    |-- KotlinxLocalTimeTS.kt...| kotlinx.datetime.LocalTime type serializer for db-messiah
    `-- KotlinxTimeTS.kt........| kotlinx.datetime serializers grouped for each database



Sources

src/
|-- main...............................| Already described in architecture.
`-- test
    |-- kotlin
    |   |-- impl
    |   |   |-- Test_Contract.kt.......| Testing interface for all db tests.
    |   |   |-- Test_Db2.kt
    |   |   |-- Test_Derby.kt
    |   |   |-- Test_H2.kt
    |   |   |-- Test_Maria.kt
    |   |   |-- Test_Mssql.kt
    |   |   |-- Test_Mysql.kt
    |   |   |-- Test_Oracle.kt
    |   |   |-- Test_Postgresql.kt
    |   |   `-- Test_Sqlite.kt
    |   |-- Test_InstantJS.kt
    |   |-- Test_LocalDateJS.kt
    |   |-- Test_LocalTimeJS.kt
    |   |-- Test_README.kt.............| Code from where README.md is generated.
    |   |-- Test_README.md.............| Template from where README.md is generated.
    |   |-- Test_UUIDJS.kt
    |   `-- utils
    |       |-- domain.kt
    |       |-- Schemas.kt
    |       `-- Serializers.kt
    `-- resources
        `-- log4j2.xml