Skip to content
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
32 changes: 23 additions & 9 deletions lib/src/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ class PostgreSQLConnection extends Object
/// [queryTimeoutInSeconds] refers to the default timeout for [PostgreSQLExecutionContext]'s execute and query methods.
/// [timeZone] is the timezone the connection is in. Defaults to 'UTC'.
/// [useSSL] when true, uses a secure socket when connecting to a PostgreSQL database.
PostgreSQLConnection(this.host, this.port, this.databaseName,
{this.username,
this.password,
this.timeoutInSeconds = 30,
this.queryTimeoutInSeconds = 30,
this.timeZone = 'UTC',
this.useSSL = false}) {
PostgreSQLConnection(
this.host,
this.port,
this.databaseName, {
this.username,
this.password,
this.timeoutInSeconds = 30,
this.queryTimeoutInSeconds = 30,
this.timeZone = 'UTC',
this.useSSL = false,
this.isUnixSocket = false,
}) {
_connectionState = _PostgreSQLConnectionStateClosed();
_connectionState.connection = this;
}
Expand Down Expand Up @@ -82,6 +87,9 @@ class PostgreSQLConnection extends Object
/// The processID of this backend.
int get processID => _processID;

/// If true, connection is made via unix socket.
final bool isUnixSocket;

/// Stream of notification from the database.
///
/// Listen to this [Stream] to receive events from PostgreSQL NOTIFY commands.
Expand Down Expand Up @@ -137,8 +145,14 @@ class PostgreSQLConnection extends Object

try {
_hasConnectedPreviously = true;
_socket = await Socket.connect(host, port)
.timeout(Duration(seconds: timeoutInSeconds));
if (isUnixSocket) {
_socket = await Socket.connect(
InternetAddress(host, type: InternetAddressType.unix), port)
.timeout(Duration(seconds: timeoutInSeconds));
} else {
_socket = await Socket.connect(host, port)
.timeout(Duration(seconds: timeoutInSeconds));
}

_framer = MessageFramer();
if (useSSL) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1.1
homepage: https://github.com/stablekernel/postgresql-dart

environment:
sdk: ">=2.2.0 <3.0.0"
sdk: ">=2.8.0 <3.0.0"

dependencies:
buffer: ^1.0.6
Expand Down