Skip to content

Commit

Permalink
Separate ColumnDescription from FieldDescription. (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Oct 15, 2023
1 parent 57b58b9 commit 5582be7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
18 changes: 12 additions & 6 deletions lib/src/v2/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,15 @@ abstract mixin class _PostgreSQLExecutionContextMixin

final queryResult =
await _enqueue(query, timeoutInSeconds: timeoutInSeconds);
var columnDescriptions = query.fieldDescriptions;
var fieldDescriptions = query.fieldDescriptions;
if (resolveOids) {
columnDescriptions = await _connection._oidCache
._resolveTableNames(this, columnDescriptions);
fieldDescriptions = await _connection._oidCache
._resolveTableNames(this, fieldDescriptions);
}
final metaData = _PostgreSQLResultMetaData(columnDescriptions!);
final metaData = _PostgreSQLResultMetaData(fieldDescriptions!
.map((e) => ColumnDescription(
typeId: e.typeId, tableName: e.tableName, columnName: e.columnName))
.toList());

return _PostgreSQLResult(
queryResult.affectedRowCount,
Expand Down Expand Up @@ -598,8 +601,11 @@ abstract mixin class _PostgreSQLExecutionContextMixin
final result = await _enqueue(query, timeoutInSeconds: timeoutInSeconds);

final affectedRowCount = result.affectedRowCount;
final columnDescriptions = query.fieldDescriptions ?? [];
final metaData = _PostgreSQLResultMetaData(columnDescriptions);
final fieldDescriptions = query.fieldDescriptions ?? [];
final metaData = _PostgreSQLResultMetaData(fieldDescriptions
.map((e) => ColumnDescription(
typeId: e.typeId, tableName: e.tableName, columnName: e.columnName))
.toList());

final value = result.value;
late final List<PostgreSQLResultRow> rows;
Expand Down
14 changes: 10 additions & 4 deletions lib/src/v2/execution_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,21 @@ abstract class PostgreSQLExecutionContext {
}

/// A description of a column.
abstract class ColumnDescription {
class ColumnDescription {
/// The name of the column returned by the query.
String get columnName;
final String columnName;

/// The resolved name of the referenced table.
String get tableName;
final String tableName;

/// The Object Identifier of the column type.
int get typeId;
final int typeId;

ColumnDescription({
required this.typeId,
required this.tableName,
required this.columnName,
});
}

/// A single row of a query result.
Expand Down
6 changes: 1 addition & 5 deletions lib/src/v2/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,16 @@ class ParameterValue extends PgTypedParameter {
: super(type ?? PgDataType.unspecified, value);
}

class FieldDescription implements ColumnDescription {
class FieldDescription {
final PostgresBinaryDecoder converter;

@override
final String columnName;
final int tableID;
final int columnID;
@override
final int typeId;
final int dataTypeSize;
final int typeModifier;
final int formatCode;

@override
final String tableName;

FieldDescription._(
Expand Down
31 changes: 8 additions & 23 deletions lib/src/v2/v2_v3_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,40 +252,25 @@ class _PostgreSQLResult extends UnmodifiableListView<PostgreSQLResultRow>

@override
late final columnDescriptions = _result.schema.columns
.map((e) => _ColumnDescription(
e.type.oid ?? 0,
e.tableName ?? '',
e.columnName ?? '',
.map((e) => ColumnDescription(
typeId: e.type.oid ?? 0,
tableName: e.tableName ?? '',
columnName: e.columnName ?? '',
))
.toList();
}

class _ColumnDescription implements ColumnDescription {
@override
final int typeId;
@override
final String tableName;
@override
final String columnName;

_ColumnDescription(
this.typeId,
this.tableName,
this.columnName,
);
}

class _PostgreSQLResultRow extends UnmodifiableListView
implements PostgreSQLResultRow {
final PgResultRow _row;
_PostgreSQLResultRow(this._row, super.source);

@override
late final columnDescriptions = _row.schema.columns
.map((e) => _ColumnDescription(
e.type.oid ?? 0,
e.tableName ?? '',
e.columnName ?? '',
.map((e) => ColumnDescription(
typeId: e.type.oid ?? 0,
tableName: e.tableName ?? '',
columnName: e.columnName ?? '',
))
.toList();

Expand Down

0 comments on commit 5582be7

Please sign in to comment.