Skip to content

Commit 18b22c5

Browse files
authored
Add replication mode flag (v3) (#124)
1 parent 46c3ff8 commit 18b22c5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/postgres_v3_experimental.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:io';
33

44
import 'package:collection/collection.dart';
5+
import 'package:postgres/src/replication.dart';
56
import 'package:stream_channel/stream_channel.dart';
67

78
import 'src/v3/connection.dart';
@@ -359,11 +360,26 @@ final class PgSessionSettings {
359360
/// For an example, see `example/v3/transformer.dart`.
360361
final StreamChannelTransformer<BaseMessage, BaseMessage>? transformer;
361362

363+
/// The replication mode for connecting in streaming replication mode.
364+
///
365+
/// The default value is [ReplicationMode.none]. But when the value is set to
366+
/// [ReplicationMode.physical] or [ReplicationMode.logical], the connection
367+
/// will be established in replication mode.
368+
///
369+
/// Please note, while in replication mode, only the Simple Query Protcol can
370+
/// be used to execute queries.
371+
///
372+
/// For more info, see [Streaming Replication Protocol]
373+
///
374+
/// [Streaming Replication Protocol]: https://www.postgresql.org/docs/current/protocol-replication.html
375+
final ReplicationMode replicationMode;
376+
362377
PgSessionSettings({
363378
this.connectTimeout,
364379
this.timeZone,
365380
this.onBadSslCertificate,
366381
this.transformer,
382+
this.replicationMode = ReplicationMode.none
367383
});
368384
}
369385

lib/src/v3/connection.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:collection/collection.dart';
88
import 'package:pool/pool.dart';
99
import 'package:postgres/postgres_v3_experimental.dart';
1010
import 'package:postgres/src/query.dart';
11+
import 'package:postgres/src/replication.dart';
1112
import 'package:stream_channel/stream_channel.dart';
1213

1314
import '../auth/auth.dart';
@@ -37,6 +38,8 @@ class _ResolvedSettings {
3738
final String timeZone;
3839
//final Encoding encoding;
3940

41+
final ReplicationMode replicationMode;
42+
4043
final StreamChannelTransformer<BaseMessage, BaseMessage>? transformer;
4144

4245
_ResolvedSettings(
@@ -49,7 +52,8 @@ class _ResolvedSettings {
4952
//queryTimeout = settings?.connectTimeout ?? const Duration(minutes: 5),
5053
timeZone = settings?.timeZone ?? 'UTC',
5154
// encoding = settings?.encoding ?? utf8,
52-
transformer = settings?.transformer;
55+
transformer = settings?.transformer,
56+
replicationMode = settings?.replicationMode ?? ReplicationMode.none;
5357

5458
bool onBadSslCertificate(X509Certificate certificate) {
5559
return settings?.onBadSslCertificate?.call(certificate) ?? false;
@@ -304,7 +308,7 @@ class PgConnectionImplementation extends _PgSessionBase
304308
_settings.endpoint.database,
305309
_settings.timeZone,
306310
username: _settings.username,
307-
// todo: Replication
311+
replication: _settings.replicationMode,
308312
));
309313

310314
return result._done.future;

0 commit comments

Comments
 (0)