Skip to content

Commit

Permalink
Add Interval to Postgres simple types.
Browse files Browse the repository at this point in the history
io.r2dbc.postgresql.codec.Interval is now considered a simple type.

Closes #573
Original pull request: #574.
  • Loading branch information
slutmaker authored and mp911de committed Apr 6, 2021
1 parent 41c8a87 commit b7f9d7c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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;

}

}

0 comments on commit b7f9d7c

Please sign in to comment.