tpolecat / doobie

Functional JDBC layer for Scala.
MIT License
2.13k stars 348 forks source link

More precise typechecking using vendor types #2023

Closed jatcwang closed 2 months ago

jatcwang commented 2 months ago

The main motivation is to provide more precise typechecking information when dealing with date & time types, because each database driver report vastly different JDBC types.

For example, in PostgreSQL the correct DB column type to store a java.time.Instant is TIMESTAMP WITH TIMEZONE (TIMESTAMPTZ). However, PostgreSQL JDBC driver reports the this column as JdbcType.Timestamp instead of JdbcType.TimestampWithTimezone. It also reports JdbcType.Timestamp for TIMESTAMP column type, which means we cannot meaningfully typecheck the query handling Instants with just JdbcType alone. The saving grace is JDBC's vendorTypeName, which Postgres correctly differentiates between TIMESTAMPTZ and TIMESTAMP.

Main changes: