From 174e27ee7dcb04ab4a4eb9e2e1c6eec92a93c004 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Sat, 14 Sep 2024 12:44:53 +0200 Subject: [PATCH] Finalizing type codec API --- CHANGELOG.md | 2 +- README.md | 7 ++++++- lib/src/types.dart | 8 ++++++++ lib/src/types/type_registry.dart | 7 +++++-- pubspec.yaml | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae81ce..af9389a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 3.4.0-dev.2 +## 3.4.0 - `Connection.info` (through `ConnectionInfo` class) exposes read-only connection-level information, e.g. acessing access server-provided parameter status values. diff --git a/README.md b/README.md index 579ca68..4e89022 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,12 @@ See the API documentation: https://pub.dev/documentation/postgres/latest/ The library supports connection pooling (and masking the connection pool as regular session executor). -## Additional Capabilities +## Custom type codecs + +The library supports registering custom type codecs (and generic object encoders) +through the`ConnectionSettings.typeRegistry`. + +## Streaming replication protocol The library supports connecting to PostgreSQL using the [Streaming Replication Protocol][]. See [Connection][] documentation for more info. diff --git a/lib/src/types.dart b/lib/src/types.dart index 8efd078..fdfb2d1 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -405,6 +405,14 @@ abstract class Type { @override String toString() => 'Type(oid:$oid)'; + + @override + int get hashCode => oid ?? -1; + + @override + bool operator ==(Object other) { + return (other is Type) && (other.oid == oid && oid != 0 && oid != null); + } } class TypedValue { diff --git a/lib/src/types/type_registry.dart b/lib/src/types/type_registry.dart index f10fc77..0226dad 100644 --- a/lib/src/types/type_registry.dart +++ b/lib/src/types/type_registry.dart @@ -237,6 +237,8 @@ final _builtInTypeNames = { '_varchar': Type.varCharArray, }; +/// Contains the static registry of type mapping from substitution names to +/// type OIDs, their codec and the generic type encoders (for un-typed values). class TypeRegistry { final _byTypeOid = {}; final _bySubstitutionName = {}; @@ -247,8 +249,9 @@ class TypeRegistry { /// Override or extend the built-in codecs using the type OID as key. Map? codecs, - /// When encoding an untyped parameter for a query, try to use these encoders - /// before the built-in (generic) text encoders. + /// When encoding a non-typed parameter for a query, try to use these + /// encoders in their specified order. The encoders will be called + /// before the the built-in (generic) text encoders. Iterable? encoders, }) { _bySubstitutionName.addAll(_builtInTypeNames); diff --git a/pubspec.yaml b/pubspec.yaml index fcc5cb2..abb7bcd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: postgres description: PostgreSQL database driver. Supports statement reuse and binary protocol and connection pooling. -version: 3.4.0-dev.2 +version: 3.4.0 homepage: https://github.com/isoos/postgresql-dart topics: - sql