File tree Expand file tree Collapse file tree 7 files changed +24
-12
lines changed Expand file tree Collapse file tree 7 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import 'dart:convert';
3
3
4
4
import 'package:collection/collection.dart' ;
5
5
import 'package:meta/meta.dart' ;
6
+ import 'package:postgres/src/types/type_registry.dart' ;
6
7
import 'package:stream_channel/stream_channel.dart' ;
7
8
8
9
import 'src/replication.dart' ;
@@ -436,13 +437,18 @@ class ConnectionSettings extends SessionSettings {
436
437
/// [Streaming Replication Protocol] : https://www.postgresql.org/docs/current/protocol-replication.html
437
438
final ReplicationMode ? replicationMode;
438
439
440
+ /// When set, use the type registry with custom types, instead of the
441
+ /// built-in ones provided by the package.
442
+ final TypeRegistry ? typeRegistry;
443
+
439
444
ConnectionSettings ({
440
445
this .applicationName,
441
446
this .timeZone,
442
447
this .encoding,
443
448
this .sslMode,
444
449
this .transformer,
445
450
this .replicationMode,
451
+ this .typeRegistry,
446
452
super .connectTimeout,
447
453
super .queryTimeout,
448
454
super .queryMode,
Original file line number Diff line number Diff line change @@ -585,7 +585,8 @@ class PostgresBinaryDecoder {
585
585
case TypeOid .regtype:
586
586
final data = input.buffer.asByteData (input.offsetInBytes, input.length);
587
587
final oid = data.getInt32 (0 );
588
- return TypeRegistry .instance.resolveOid (oid);
588
+ // TODO: DecodeInput may provide the connection-level TypeRegistry
589
+ return TypeRegistry ().resolveOid (oid);
589
590
case TypeOid .voidType:
590
591
return null ;
591
592
Original file line number Diff line number Diff line change @@ -71,10 +71,6 @@ final _builtInTypes = <Type>{
71
71
};
72
72
73
73
class TypeRegistry {
74
- // TODO: implement connection-level registry
75
- @internal
76
- static final instance = TypeRegistry ();
77
-
78
74
final _byTypeOid = < int , Type > {};
79
75
final _bySubstitutionName = < String , Type > {};
80
76
@@ -110,6 +106,7 @@ class TypeRegistry {
110
106
111
107
Type ? resolveSubstitution (String name) => _bySubstitutionName[name];
112
108
109
+ /// Note: this returns only types with oids.
113
110
@internal
114
- Iterable <Type > get values => _byTypeOid.values;
111
+ Iterable <Type > get registered => _byTypeOid.values;
115
112
}
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import 'package:async/async.dart' as async;
7
7
import 'package:charcode/ascii.dart' ;
8
8
import 'package:meta/meta.dart' ;
9
9
import 'package:pool/pool.dart' as pool;
10
- import 'package:postgres/src/types/type_registry.dart' ;
11
10
import 'package:stream_channel/stream_channel.dart' ;
12
11
13
12
import '../../postgres.dart' ;
@@ -658,7 +657,8 @@ class _PgResultStreamSubscription
658
657
for (final field in message.fieldDescriptions)
659
658
ResultSchemaColumn (
660
659
typeOid: field.typeOid,
661
- type: TypeRegistry .instance.resolveOid (field.typeOid),
660
+ type: session._connection._settings.typeRegistry
661
+ .resolveOid (field.typeOid),
662
662
columnName: field.fieldName,
663
663
columnOid: field.columnOid,
664
664
tableOid: field.tableOid,
Original file line number Diff line number Diff line change 1
1
import 'dart:convert' ;
2
2
3
3
import 'package:postgres/messages.dart' ;
4
+ import 'package:postgres/src/types/type_registry.dart' ;
4
5
import 'package:stream_channel/stream_channel.dart' ;
5
6
6
7
import '../../postgres.dart' ;
@@ -50,6 +51,8 @@ class ResolvedConnectionSettings extends ResolvedSessionSettings
50
51
final StreamChannelTransformer <Message , Message >? transformer;
51
52
@override
52
53
final ReplicationMode replicationMode;
54
+ @override
55
+ final TypeRegistry typeRegistry;
53
56
54
57
ResolvedConnectionSettings (
55
58
ConnectionSettings ? super .settings, ConnectionSettings ? super .fallback)
@@ -62,7 +65,10 @@ class ResolvedConnectionSettings extends ResolvedSessionSettings
62
65
transformer = settings? .transformer ?? fallback? .transformer,
63
66
replicationMode = settings? .replicationMode ??
64
67
fallback? .replicationMode ??
65
- ReplicationMode .none;
68
+ ReplicationMode .none,
69
+ // TODO: consider merging the type registries
70
+ typeRegistry =
71
+ settings? .typeRegistry ?? fallback? .typeRegistry ?? TypeRegistry ();
66
72
67
73
bool isMatchingConnection (ResolvedConnectionSettings other) {
68
74
return isMatchingSession (other) &&
Original file line number Diff line number Diff line change @@ -386,7 +386,8 @@ class VariableTokenizer {
386
386
387
387
if (consumedColonForType) {
388
388
final typeName = typeBuffer.toString ();
389
- final type = TypeRegistry .instance.resolveSubstitution (typeName);
389
+ // TODO: get this from the connection settings
390
+ final type = TypeRegistry ().resolveSubstitution (typeName);
390
391
if (type == null ) {
391
392
error ('Unknown type: $typeName ' );
392
393
}
Original file line number Diff line number Diff line change @@ -15,11 +15,12 @@ void main() {
15
15
Type .serial,
16
16
};
17
17
18
- for (final type in TypeRegistry .instance.values ) {
18
+ for (final type in TypeRegistry ().registered ) {
19
19
if (withoutMapping.contains (type)) continue ;
20
20
21
21
expect (
22
- PostgreSQLFormatIdentifier .typeStringToCodeMap.values.contains (type),
22
+ PostgreSQLFormatIdentifier .typeStringToCodeMap.registered
23
+ .contains (type),
23
24
true ,
24
25
reason: 'There should be a type mapping for $type ' ,
25
26
);
You can’t perform that action at this time.
0 commit comments