diff --git a/CHANGELOG.md b/CHANGELOG.md index a99902a3..cac79d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.5.10 + +- Supporting `BYTEA[]` built-in type. + ## 3.5.9 - Supporting multiple hosts in connection strings via comma-separated hosts or multiple `host` query parameters. diff --git a/lib/src/types.dart b/lib/src/types.dart index e6025b57..316bb47a 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -284,6 +284,13 @@ abstract class Type { /// Each element of the list must fit into a byte (0-255). static const byteArray = GenericType>(TypeOid.byteArray); + /// Must be a [List>]. + /// + /// Each inner list must be a valid bytea value. + static const byteArrayArray = GenericType>>( + TypeOid.byteArrayArray, + ); + /// Must be a [String] /// /// Used for internal pg structure names diff --git a/lib/src/types/binary_codec.dart b/lib/src/types/binary_codec.dart index 65578b7e..e626647a 100644 --- a/lib/src/types/binary_codec.dart +++ b/lib/src/types/binary_codec.dart @@ -247,6 +247,22 @@ class PostgresBinaryEncoder { ); } + case TypeOid.byteArrayArray: + { + if (input is List) { + return _writeListBytes>( + _castOrThrowList>(input), + TypeOid.byteArray, + (item) => item.length, + (writer, item) => writer.write(item), + encoding, + ); + } + throw FormatException( + 'Invalid type for parameter value. Expected: List?> Got: ${input.runtimeType}', + ); + } + case TypeOid.uuid: { if (input is! String) { @@ -894,6 +910,12 @@ class PostgresBinaryDecoder { case TypeOid.byteArray: return input; + case TypeOid.byteArrayArray: + return readListBytes( + input, + (reader, length) => reader.read(length), + ); + case TypeOid.uuid: return _decodeUuid(input); case TypeOid.uuidArray: diff --git a/lib/src/types/type_registry.dart b/lib/src/types/type_registry.dart index 00cb72cc..4b8759c6 100644 --- a/lib/src/types/type_registry.dart +++ b/lib/src/types/type_registry.dart @@ -16,6 +16,7 @@ class TypeOid { static const booleanArray = 1000; static const box = 603; static const byteArray = 17; + static const byteArrayArray = 1001; static const character = 1042; static const circle = 718; static const date = 1082; @@ -86,6 +87,7 @@ final _builtInTypes = { Type.interval, Type.numeric, Type.byteArray, + Type.byteArrayArray, Type.date, Type.json, Type.jsonb, @@ -141,6 +143,7 @@ final _builtInCodecs = { TypeOid.interval: GenericCodec(TypeOid.interval), TypeOid.numeric: GenericCodec(TypeOid.numeric), TypeOid.byteArray: GenericCodec(TypeOid.byteArray), + TypeOid.byteArrayArray: GenericCodec(TypeOid.byteArrayArray), TypeOid.date: GenericCodec(TypeOid.date), TypeOid.json: GenericCodec(TypeOid.json, encodesNull: true), TypeOid.jsonb: GenericCodec(TypeOid.jsonb, encodesNull: true), @@ -180,6 +183,7 @@ final _builtInTypeNames = { 'bigint': Type.bigInteger, 'boolean': Type.boolean, 'bytea': Type.byteArray, + '_bytea': Type.byteArrayArray, 'bpchar': Type.character, 'char': Type.character, 'character': Type.character, diff --git a/pubspec.yaml b/pubspec.yaml index d05361df..1e79e52b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: postgres description: PostgreSQL database driver. Supports binary protocol, connection pooling and statement reuse. -version: 3.5.9 +version: 3.5.10 homepage: https://github.com/isoos/postgresql-dart topics: - sql