Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSqlType - Change "PGInterval" to "String #5403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Aug 14, 2024

PostgreSqlType INTERVAL was initially mapped as PgInterval

https://github.com/cashapp/sqldelight/blob/431caee2a99885719b1a43db2e08ef16a3b64af8/dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlType.kt#L21

This 🥨 changes the mapping to String as org.postgresql.util.PgInterval is a JDBC type and would be consistent with JSON, TSVECTOR, XML type mapping. The client can use a type adapter for the string value to a desired platform type - Duration, Period ... etc. Docs page updated with type mapping

Requirement -
Write to an Interval column using setObject Other, as this is required for it to interpret as an interval type
Read from an Interval column usinggetString, this is formatted using the intervalstyle* PG client option

  • For example, "-c intervalstyle=iso_8601" can be set on the client connection options and used with a custom kotlin.time.Duration column adapter as intended by SqlDelight to encode/decode iso interval values

Note:
Future Developments

  • PostgreSqlType dialect type should not reference JDBC (java.sql) types as not all drivers are JDBC
  • There should be specific driver dialect subclasses (PostgreSql JDBC, PostgreSql R2DBC) without the need to create a new dialect
    • e.g PostgreSql JDBC has PGobject types for JSON, Interval that setObject can use
    • e.g PostgreSql R2DBC needs a specific codec class for JSON type that currently cannot be used in statements

@griffio griffio force-pushed the fix-postgresql-interval branch 2 times, most recently from 5f99018 to 6fc7138 Compare September 23, 2024 12:07
@griffio griffio marked this pull request as ready for review September 30, 2024 12:08
PGInterval is a JDBC type
The client should choose how to adapt the String into PGInterval, Duration, Period etc depending on platform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant