Skip to content

Commit 1b8e52f

Browse files
committed
add support for interval
1 parent 9f66256 commit 1b8e52f

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

lib/src/binary_codec.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ class PostgresBinaryEncoder extends Converter<dynamic, Uint8List?> {
148148
'Invalid type for parameter value. Expected: DateTime Got: ${value.runtimeType}');
149149
}
150150

151+
case PostgreSQLDataType.interval:
152+
{
153+
if (value is Duration) {
154+
final bd = ByteData(8);
155+
bd.setInt64(0, value.inMicroseconds);
156+
return bd.buffer.asUint8List();
157+
}
158+
throw FormatException(
159+
'Invalid type for parameter value. Expected: Duration Got: ${value.runtimeType}');
160+
}
161+
151162
case PostgreSQLDataType.numeric:
152163
{
153164
if (value is double || value is int) {
@@ -422,6 +433,9 @@ class PostgresBinaryDecoder extends Converter<Uint8List, dynamic> {
422433
return DateTime.utc(2000)
423434
.add(Duration(microseconds: buffer.getInt64(0)));
424435

436+
case PostgreSQLDataType.interval:
437+
return Duration(microseconds: buffer.getInt64(0));
438+
425439
case PostgreSQLDataType.numeric:
426440
return _decodeNumeric(value);
427441

@@ -541,6 +555,7 @@ class PostgresBinaryDecoder extends Converter<Uint8List, dynamic> {
541555
1082: PostgreSQLDataType.date,
542556
1114: PostgreSQLDataType.timestampWithoutTimezone,
543557
1184: PostgreSQLDataType.timestampWithTimezone,
558+
1186: PostgreSQLDataType.interval,
544559
1700: PostgreSQLDataType.numeric,
545560
2950: PostgreSQLDataType.uuid,
546561
3802: PostgreSQLDataType.jsonb,

lib/src/query.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class PostgreSQLFormatIdentifier {
321321
'date': PostgreSQLDataType.date,
322322
'timestamp': PostgreSQLDataType.timestampWithoutTimezone,
323323
'timestamptz': PostgreSQLDataType.timestampWithTimezone,
324+
'interval': PostgreSQLDataType.interval,
324325
'numeric': PostgreSQLDataType.numeric,
325326
'jsonb': PostgreSQLDataType.jsonb,
326327
'bytea': PostgreSQLDataType.byteArray,

lib/src/substituter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class PostgreSQLFormat {
3737
return 'timestamp';
3838
case PostgreSQLDataType.timestampWithTimezone:
3939
return 'timestamptz';
40+
case PostgreSQLDataType.interval:
41+
return 'interval';
4042
case PostgreSQLDataType.numeric:
4143
return 'numeric';
4244
case PostgreSQLDataType.date:

lib/src/types.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ enum PostgreSQLDataType {
4242
/// Must be a [DateTime] (microsecond date and time precision)
4343
timestampWithTimezone,
4444

45+
/// Must be a [Duration]
46+
interval,
47+
4548
/// Must be a [List<int>]
4649
numeric,
4750

0 commit comments

Comments
 (0)