Skip to content

Add PostgreSQL JDBC database module - #725

Open
dsudomoin wants to merge 2 commits into
kora-projects:masterfrom
dsudomoin:feature/postgres-jdbc-module
Open

Add PostgreSQL JDBC database module#725
dsudomoin wants to merge 2 commits into
kora-projects:masterfrom
dsudomoin:feature/postgres-jdbc-module

Conversation

@dsudomoin

@dsudomoin dsudomoin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

New database-jdbc-postgres module with PostgreSQL-specific JDBC mappers, plus a
refactor of database-jdbc that splits the monolithic JdbcMapperModule into
focused mapper modules the new module builds on.

database-jdbc (refactor + additions)

  • Split into PrimitiveJdbcMappersModule, TemporalJdbcMappersModule (incl. Instant),
    CollectionJdbcResultSetMappersModule
  • SQL array infrastructure (ArrayColumnData, Collection↔array mappers)
  • Enum foundation EnumColumnData<E,V> — name / ordinal / custom value / native type,
    with value-mapper delegation

database-jdbc-postgres (new)

  • PostgresJdbcDatabaseModule aggregator
  • PgIntervalJdbcMappersModule: Duration and PeriodPGInterval
  • PostgresArrayColumnDataModule: array defaults incl. enum arrays; = ANY(?) for IN-lists
  • Native enum via PGobject with correct SQL NULL handling for typed columns
  • @JsonPGobject(jsonb) bridge (json as compileOnly, opt-in module)
  • Range types: int4 / int8 / num / date / ts / tstz with quoted bounds

json-common

  • bigDecimalJsonReader now also reads BigDecimal from a JSON string (VALUE_STRING),
    not just numeric tokens

Testing

  • ./gradlew :database:database-jdbc:test :database:database-jdbc-postgres:test :json:json-common:test — green
  • Unit tests for every mapper/factory + Testcontainers integration round-trips on a real
    PostgreSQL: arrays, = ANY(?), ranges (incl. ts/tstz), native enum (incl. NULL), jsonb,
    Duration/Period intervals

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

Dependency Update Report

Update level: patch

Found 3 dependency updates.

gradle/libs.versions.toml

  • s3client-aws (software.amazon.awssdk:s3, inline:254): 2.47.5 -> 2.47.6
  • zeebe: 8.9.12 -> 8.9.13
  • kotlin-stdlib: 2.4.0 -> 2.4.10

@dsudomoin
dsudomoin force-pushed the feature/postgres-jdbc-module branch from fddf1bb to 45b5143 Compare July 15, 2026 19:15
Introduces database-jdbc-postgres with PostgreSQL-specific JDBC mappers, and
refactors the monolithic JdbcMapperModule in database-jdbc into focused mapper
modules the new module builds upon.

database-jdbc (refactor + additions):
- Split JdbcMapperModule into PrimitiveJdbcMappersModule, TemporalJdbcMappersModule
  (incl. Instant) and CollectionJdbcResultSetMappersModule
- SQL array infrastructure (ArrayColumnData, Collection<->array mappers)
- Enum mapping foundation (EnumColumnData<E,V> supporting name/ordinal/custom value
  and native type, with value-mapper delegation)

database-jdbc-postgres (new):
- PostgresJdbcDatabaseModule aggregating the Postgres mappers
- PgIntervalJdbcMappersModule: Duration and Period <-> PGInterval
- PostgresArrayColumnDataModule: array defaults incl. enum arrays; = ANY(?) support
- Native enum via PGobject with correct SQL NULL handling for typed columns
- @JSON <-> PGobject(jsonb) bridge (json as compileOnly, opt-in module)
- Range types: int4/int8/num/date/ts/tstz with quoted bounds

All mappers covered by unit tests and Testcontainers integration round-trips.

Claude-Session: https://claude.ai/code/session_019pHSDuY1pScyt8n3ExdVHm
bigDecimalJsonReader now accepts a VALUE_STRING token (e.g. "123.45") in
addition to numeric tokens, so a BigDecimal serialized as a JSON string
round-trips without losing precision.

Claude-Session: https://claude.ai/code/session_019pHSDuY1pScyt8n3ExdVHm
@dsudomoin
dsudomoin force-pushed the feature/postgres-jdbc-module branch from 45b5143 to ee954c7 Compare July 15, 2026 21:51
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

class JsonNumberTests extends Assertions implements JsonModule {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем?
И сообщи там агенту, что экстендить Assertions - рак.

@@ -230,8 +230,9 @@ default JsonWriter<BigDecimal> bigDecimalJsonWriter() {
default JsonReader<BigDecimal> bigDecimalJsonReader() {
return parser -> switch (parser.currentToken()) {
case VALUE_NULL -> null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Таким образом нарушился контракт между reader-writer, так что нет.

package io.koraframework.database.jdbc;

@FunctionalInterface
public interface JdbcEnumValueMappingStrategy {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, я этот мусор один раз не пропустил и второй раз не пропущу.

import java.util.Optional;
import java.util.Set;

public interface CollectionJdbcResultSetMappersModule {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не думаю, что кому-то нужно селектить сеты и коллекции вместо листов.

import java.time.Duration;
import java.time.Period;

public interface PgIntervalJdbcMappersModule {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все мапперы в модулях должны поставляться с тегом.


import java.util.function.Function;

public record ArrayColumnData<T>(String sqlTypeName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давайте не хранить какую-то мутную метадату, а просто если очень уж хочется сделать маппер в обе стороны и класть в контейнер его, а не врапперы мапперов.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants