Skip to content

Commit

Permalink
Finalizing type codec API
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Sep 14, 2024
1 parent c212668 commit 174e27e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ abstract class Type<T extends Object> {

@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<T extends Object> {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/types/type_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ final _builtInTypeNames = <String, Type>{
'_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 = <int, Type>{};
final _bySubstitutionName = <String, Type>{};
Expand All @@ -247,8 +249,9 @@ class TypeRegistry {
/// Override or extend the built-in codecs using the type OID as key.
Map<int, Codec>? 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<EncoderFn>? encoders,
}) {
_bySubstitutionName.addAll(_builtInTypeNames);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 174e27e

Please sign in to comment.