|
23 | 23 | import io.r2dbc.postgresql.codec.Box; |
24 | 24 | import io.r2dbc.postgresql.codec.Circle; |
25 | 25 | import io.r2dbc.postgresql.codec.EnumCodec; |
| 26 | +import io.r2dbc.postgresql.codec.Interval; |
26 | 27 | import io.r2dbc.postgresql.codec.Line; |
27 | 28 | import io.r2dbc.postgresql.codec.Lseg; |
28 | 29 | import io.r2dbc.postgresql.codec.Path; |
|
34 | 35 | import lombok.Data; |
35 | 36 | import reactor.test.StepVerifier; |
36 | 37 |
|
| 38 | +import java.time.Duration; |
37 | 39 | import java.util.Arrays; |
38 | 40 | import java.util.Collections; |
39 | 41 | import java.util.List; |
@@ -245,6 +247,27 @@ void shouldReadAndWriteGeoTypes() { |
245 | 247 | assertThat(saved).isEqualTo(loaded); |
246 | 248 | } |
247 | 249 |
|
| 250 | + @Test // gh-573 |
| 251 | + void shouldReadAndWriteInterval() { |
| 252 | + EntityWithInterval entityWithInterval = new EntityWithInterval(); |
| 253 | + entityWithInterval.interval = Interval.of(Duration.ofHours(3)); |
| 254 | + |
| 255 | + template.execute("DROP TABLE IF EXISTS with_interval"); |
| 256 | + template.execute("CREATE TABLE with_interval (" // |
| 257 | + + "id serial PRIMARY KEY," // |
| 258 | + + "interval INTERVAL" // |
| 259 | + + ")"); |
| 260 | + |
| 261 | + R2dbcEntityTemplate template = new R2dbcEntityTemplate(client, |
| 262 | + new DefaultReactiveDataAccessStrategy(PostgresDialect.INSTANCE)); |
| 263 | + |
| 264 | + EntityWithInterval saved = template.insert(entityWithInterval).block(); |
| 265 | + EntityWithInterval loaded = template.select(Query.empty(), EntityWithInterval.class) // |
| 266 | + .blockLast(); |
| 267 | + |
| 268 | + assertThat(saved.interval).isEqualTo(loaded.interval); |
| 269 | + } |
| 270 | + |
248 | 271 | private void insert(EntityWithArrays object) { |
249 | 272 |
|
250 | 273 | client.insert() // |
@@ -300,4 +323,15 @@ static class GeoType { |
300 | 323 | org.springframework.data.geo.Point springDataPoint; |
301 | 324 | org.springframework.data.geo.Polygon springDataPolygon; |
302 | 325 | } |
| 326 | + |
| 327 | + @Data |
| 328 | + @Table("with_interval") |
| 329 | + static class EntityWithInterval { |
| 330 | + |
| 331 | + @Id Integer id; |
| 332 | + |
| 333 | + Interval interval; |
| 334 | + |
| 335 | + } |
| 336 | + |
303 | 337 | } |
0 commit comments