Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeParameters fields. #360

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/postgres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ export 'src/pool/pool_api.dart';
export 'src/replication.dart';
export 'src/types.dart';
export 'src/types/codec.dart'
show
Codec,
CodecContext,
EncodedValue,
EncoderFn,
EncodingFormat,
RuntimeParameters;
show Codec, CodecContext, EncodedValue, EncoderFn, EncodingFormat;
export 'src/types/geo_types.dart';
export 'src/types/range_types.dart';
export 'src/types/text_search.dart'
show TsVector, TsWord, TsWordPos, TsWeight, TsQuery;
export 'src/types/type_registry.dart' show TypeRegistry;
export 'src/v3/relation_tracker.dart' show RelationTracker;
export 'src/v3/runtime_parameters.dart' show RuntimeParameters;

/// A description of a SQL query as interpreted by this package.
///
Expand Down
44 changes: 1 addition & 43 deletions lib/src/types/codec.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:collection';
import 'dart:convert';
import 'dart:typed_data';

import '../buffer.dart';
import '../types.dart';
import '../v3/relation_tracker.dart';
import '../v3/runtime_parameters.dart';
import 'type_registry.dart';

/// Represents the [bytes] of a received (field) or sent (parameter) value.
Expand Down Expand Up @@ -117,45 +117,3 @@ class CodecContext {
return PgByteDataWriter(encoding: encoding);
}
}

/// The read-only, passive view of the Postgresql's runtime/session parameters.
///
/// Postgresql server reports certain parameter values at opening a connection
/// or whenever their values change. Such parameters may include:
/// - `application_name`
/// - `server_version`
/// - `server_encoding`
/// - `client_encoding`
/// - `is_superuser`
/// - `session_authorization`
/// - `DateStyle`
/// - `TimeZone`
/// - `integer_datetimes`
///
/// This class holds the latest parameter values send by the server.
/// The values are not queried or updated actively.
///
/// The available parameters may be discovered following the instructions on these URLs:
/// - https://www.postgresql.org/docs/current/sql-show.html
/// - https://www.postgresql.org/docs/current/runtime-config.html
/// - https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQPARAMETERSTATUS
class RuntimeParameters {
final _values = <String, String>{};

RuntimeParameters({Map<String, String>? initialValues}) {
if (initialValues != null) {
_values.addAll(initialValues);
}
}

/// The latest values of the runtime parameters. The map is read-only.
late final latestValues = UnmodifiableMapView(_values);

String? get applicationName => latestValues['application_name'];
}

extension RuntimeParametersExt on RuntimeParameters {
void setValue(String name, String value) {
_values[name] = value;
}
}
2 changes: 1 addition & 1 deletion lib/src/v3/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import 'package:stream_channel/stream_channel.dart';
import '../../postgres.dart';
import '../auth/auth.dart';
import '../messages/logical_replication_messages.dart';
import '../types/codec.dart';
import '../types/type_registry.dart';
import 'protocol.dart';
import 'query_description.dart';
import 'relation_tracker.dart';
import 'resolved_settings.dart';
import 'runtime_parameters.dart';

const _debugLog = false;

Expand Down
49 changes: 49 additions & 0 deletions lib/src/v3/runtime_parameters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:collection';

/// The read-only, passive view of the Postgresql's runtime/session parameters.
///
/// Postgresql server reports certain parameter values at opening a connection
/// or whenever their values change. Such parameters may include:
/// - `application_name`
/// - `server_version`
/// - `server_encoding`
/// - `client_encoding`
/// - `is_superuser`
/// - `session_authorization`
/// - `DateStyle`
/// - `TimeZone`
/// - `integer_datetimes`
///
/// This class holds the latest parameter values send by the server.
/// The values are not queried or updated actively.
///
/// The available parameters may be discovered following the instructions on these URLs:
/// - https://www.postgresql.org/docs/current/sql-show.html
/// - https://www.postgresql.org/docs/current/runtime-config.html
/// - https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQPARAMETERSTATUS
class RuntimeParameters {
final _values = <String, String>{};

RuntimeParameters({Map<String, String>? initialValues}) {
if (initialValues != null) {
_values.addAll(initialValues);
}
}

/// The latest values of the runtime parameters. The map is read-only.
late final latestValues = UnmodifiableMapView(_values);

String? get applicationName => latestValues['application_name'];
String? get clientEncoding => latestValues['client_encoding'];
String? get dateStyle => latestValues['DateStyle'];
String? get integerDatetimes => latestValues['integer_datetimes'];
String? get serverEncoding => latestValues['server_encoding'];
String? get serverVersion => latestValues['server_version'];
String? get timeZone => latestValues['TimeZone'];
}

extension RuntimeParametersExt on RuntimeParameters {
void setValue(String name, String value) {
_values[name] = value;
}
}
Loading