Skip to content

Commit

Permalink
Finalizing type codec API (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Sep 16, 2024
1 parent cec8201 commit 6881361
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -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`).
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);
}
}

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 6881361

Please sign in to comment.