Skip to content

Add r2dbc-postgresql Interval to simple types #574

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class PostgresDialect extends org.springframework.data.relational.core.di
// conditional Postgres JSON support.
ifClassPresent("io.r2dbc.postgresql.codec.Json", simpleTypes::add);

// conditional Postgres Interval support
ifClassPresent("io.r2dbc.postgresql.codec.Interval", simpleTypes::add);

SIMPLE_TYPES = simpleTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.r2dbc.postgresql.codec.Box;
import io.r2dbc.postgresql.codec.Circle;
import io.r2dbc.postgresql.codec.EnumCodec;
import io.r2dbc.postgresql.codec.Interval;
import io.r2dbc.postgresql.codec.Line;
import io.r2dbc.postgresql.codec.Lseg;
import io.r2dbc.postgresql.codec.Path;
Expand All @@ -34,6 +35,7 @@
import lombok.Data;
import reactor.test.StepVerifier;

import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -245,6 +247,27 @@ void shouldReadAndWriteGeoTypes() {
assertThat(saved).isEqualTo(loaded);
}

@Test // gh-573
void shouldReadAndWriteInterval() {
EntityWithInterval entityWithInterval = new EntityWithInterval();
entityWithInterval.interval = Interval.of(Duration.ofHours(3));

template.execute("DROP TABLE IF EXISTS with_interval");
template.execute("CREATE TABLE with_interval (" //
+ "id serial PRIMARY KEY," //
+ "interval INTERVAL" //
+ ")");

R2dbcEntityTemplate template = new R2dbcEntityTemplate(client,
new DefaultReactiveDataAccessStrategy(PostgresDialect.INSTANCE));

EntityWithInterval saved = template.insert(entityWithInterval).block();
EntityWithInterval loaded = template.select(Query.empty(), EntityWithInterval.class) //
.blockLast();

assertThat(saved.interval).isEqualTo(loaded.interval);
}

private void insert(EntityWithArrays object) {

client.insert() //
Expand Down Expand Up @@ -300,4 +323,15 @@ static class GeoType {
org.springframework.data.geo.Point springDataPoint;
org.springframework.data.geo.Polygon springDataPolygon;
}

@Data
@Table("with_interval")
static class EntityWithInterval {

@Id Integer id;

Interval interval;

}

}