Skip to content

Commit

Permalink
Rename to DatabaseInfo (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Sep 12, 2024
1 parent cc2d3e7 commit 76601a1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
access to `encoding`, observed runtime parameters and the `TypeRegistry`.
- `EncoderFn` value converter for generic Dart object -> Postgres-encoded bytes
(for values where type is not specified).
- `RelationTracker` tracks information about relations (currently limited to `RelationMessage` caching).
- `DatabaseInfo` tracks information about relations and oids (currently limited to `RelationMessage` caching).
- **Behaviour / soft-breaking changes**:
- Removed `@internal`-annotated methods from the public API of `ServerException` and `Severity`.
- `ServerException` may be transformed into `_PgTimeoutException` which is both `PgException` and `TimeoutException` (but no longer `ServerException`).
Expand Down
2 changes: 1 addition & 1 deletion lib/postgres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export 'src/types/text_search.dart'
show TsVector, TsWord, TsWordPos, TsWeight, TsQuery;
export 'src/types/type_registry.dart' show TypeRegistry;
export 'src/v3/connection_info.dart' show ConnectionInfo;
export 'src/v3/relation_tracker.dart' show RelationTracker;
export 'src/v3/database_info.dart' show DatabaseInfo;

/// A description of a SQL query as interpreted by this package.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/logical_replication_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class TupleData {
final tupleDataType = TupleDataType.fromByte(typeId);
late final int length;
late final String data;
final typeOid = reader.codecContext.relationTracker
final typeOid = reader.codecContext.databaseInfo
.getCachedTypeOidForRelationColumn(relationId, i);
Object? value;
switch (tupleDataType) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/types/codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:typed_data';
import '../buffer.dart';
import '../types.dart';
import '../v3/connection_info.dart';
import '../v3/relation_tracker.dart';
import '../v3/database_info.dart';
import 'type_registry.dart';

/// Represents the [bytes] of a received (field) or sent (parameter) value.
Expand Down Expand Up @@ -80,27 +80,27 @@ abstract class Codec {
/// Provides access to connection and database information, and also to additional codecs.
class CodecContext {
final ConnectionInfo connectionInfo;
final DatabaseInfo databaseInfo;
final Encoding encoding;
final RelationTracker relationTracker;
final TypeRegistry typeRegistry;

CodecContext({
required this.connectionInfo,
required this.databaseInfo,
required this.encoding,
required this.relationTracker,
required this.typeRegistry,
});

factory CodecContext.withDefaults({
ConnectionInfo? connectionInfo,
DatabaseInfo? databaseInfo,
Encoding? encoding,
RelationTracker? relationTracker,
TypeRegistry? typeRegistry,
}) {
return CodecContext(
connectionInfo: connectionInfo ?? ConnectionInfo(),
databaseInfo: databaseInfo ?? DatabaseInfo(),
encoding: encoding ?? utf8,
relationTracker: relationTracker ?? RelationTracker(),
typeRegistry: typeRegistry ?? TypeRegistry(),
);
}
Expand Down
18 changes: 9 additions & 9 deletions lib/src/v3/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import '../exceptions.dart';
import '../messages/logical_replication_messages.dart';
import '../types/type_registry.dart';
import 'connection_info.dart';
import 'database_info.dart';
import 'protocol.dart';
import 'query_description.dart';
import 'relation_tracker.dart';
import 'resolved_settings.dart';

const _debugLog = false;
Expand Down Expand Up @@ -208,9 +208,9 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
: ResolvedConnectionSettings(connectionSettings, null);
final codecContext = CodecContext(
connectionInfo: ConnectionInfo(),
encoding: settings.encoding,
// TODO: share this between pooled connections
relationTracker: RelationTracker(),
databaseInfo: DatabaseInfo(),
encoding: settings.encoding,
typeRegistry: settings.typeRegistry,
);
var (channel, secure) = await _connect(
Expand Down Expand Up @@ -243,7 +243,7 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
settings,
channel,
secure,
relationTracker: codecContext.relationTracker,
databaseInfo: codecContext.databaseInfo,
info: codecContext.connectionInfo,
);
await connection._startup();
Expand Down Expand Up @@ -357,14 +357,14 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
@override
final ResolvedConnectionSettings _settings;
final StreamChannel<Message> _channel;
final RelationTracker _relationTracker;
final DatabaseInfo _databaseInfo;
@override
final ConnectionInfo info;

@internal
late final codecContext = CodecContext(
encoding: encoding,
relationTracker: _relationTracker,
databaseInfo: _databaseInfo,
connectionInfo: info,
typeRegistry: _settings.typeRegistry,
);
Expand Down Expand Up @@ -399,9 +399,9 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
this._settings,
this._channel,
this._channelIsSecure, {
required RelationTracker relationTracker,
required DatabaseInfo databaseInfo,
required this.info,
}) : _relationTracker = relationTracker {
}) : _databaseInfo = databaseInfo {
_serverMessages = _channel.stream
.listen(_handleMessage, onDone: _socketClosed, onError: (e, s) {
_close(
Expand Down Expand Up @@ -446,7 +446,7 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
if (message is XLogDataLogicalMessage) {
final embedded = message.message;
if (embedded is RelationMessage) {
_relationTracker.addRelationMessage(embedded);
_databaseInfo.addRelationMessage(embedded);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:postgres/src/messages/logical_replication_messages.dart';
/// TODO: Implement active querying using `pg_class` like the below query:
/// "SELECT relname FROM pg_class WHERE relkind='r' AND oid = ?",
/// https://www.postgresql.org/docs/current/catalog-pg-class.html
class RelationTracker {
class DatabaseInfo {
final _relationMessages = <int, RelationMessage>{};

/// Returns the type OID for [relationId] and [columnIndex].
Expand All @@ -32,7 +32,7 @@ class RelationTracker {
}
}

extension RelationTrackerExt on RelationTracker {
extension DatabaseInfoExt on DatabaseInfo {
void addRelationMessage(RelationMessage message) {
_relationMessages[message.relationId] = message;
}
Expand Down

0 comments on commit 76601a1

Please sign in to comment.