From 6881361189478079377c073dd08d3fc597e209cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Mon, 16 Sep 2024 22:46:57 +0200 Subject: [PATCH] Finalizing type codec API (#381) --- CHANGELOG.md | 4 ++-- README.md | 7 ++++++- lib/src/types.dart | 8 ++++++++ lib/src/types/type_registry.dart | 7 +++++-- pubspec.yaml | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aea58e95..6c947502 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. @@ -12,7 +12,7 @@ - `EncoderFn` value converter for generic Dart object -> Postgres-encoded bytes (for values where type is not specified). - `DatabaseInfo` tracks information about relations and oids (currently limited to `RelationMessage` caching). -- **Behaviour changes**, may be breaking in some cases: +- **Timeout-related behaviour changes**, may be breaking in some cases: - Preparing/executing a stamement on the main connection while in a `runTx` callback will throw an exception. - Setting `timeout` will try to actively cancel the current statement using a new connection. - `ServerException` may be transformed into `_PgQueryCancelledException` which is both `PgException` and `TimeoutException` (but no longer `ServerException`). diff --git a/README.md b/README.md index 579ca683..4e890225 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 8efd0785..1d02180b 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); + } } class TypedValue { diff --git a/lib/src/types/type_registry.dart b/lib/src/types/type_registry.dart index f10fc771..0226dad4 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 fcc5cb2b..abb7bcd3 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