PostgresDriver class final

PostgreSQL driver backed by package:postgres (pure Dart, pooled).

SQL handed to this driver must already use $n placeholders (the query grammar emits them; raw SQL is expanded by SqlBindings). Transactions run on a dedicated pooled connection; the executor passed to the callback is the only object that may issue queries inside the transaction.

Implemented types

Constructors

PostgresDriver({required String host, required String database, int port = 5432, String? username, String? password, String name = 'pgsql', int maxConnections = 10, PostgresSslMode sslMode = .disable, Duration connectTimeout = const Duration(seconds: 10), Duration queryTimeout = const Duration(seconds: 30), String applicationName = 'daravel'})
PostgresDriver.fromConfig(String name, ConnectionConfig connection)
The driver for a configured connection (DB_HOST, DB_PORT, DB_POOL_SIZE, DB_SSLMODE, ...), as a DatabaseDriverFactory: withDatabaseDriver('pgsql', PostgresDriver.fromConfig).
factory

Properties

applicationName → String
final
connectTimeout → Duration
final
database → String
final
dialect → SqlDialect
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
host → String
final
isConnected → bool
no setteroverride
maxConnections → int
final
name → String
Connection name as configured (sqlite, pgsql, ...).
final
password → String?
final
port → int
final
queryTimeout → Duration
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sslMode → PostgresSslMode
final
unixSocketPath → String?
The socket file when host is a path (/cloudsql/project:region:db), as libpq and Laravel read it: a directory gets .s.PGSQL.<port> appended. null for TCP hosts.
no setter
username → String?
final

Methods

close() → Future<void>
override
connect() → Future<void>
override
execute(String sql, [List<Object?> bindings = const []]) → Future<int>
Runs a statement and returns the number of affected rows.
override
insertGetId(String sql, [List<Object?> bindings = const []]) → Future<Object?>
Runs an insert and returns the generated primary key.
override
isUniqueConstraintError(Object error) → bool
SQLSTATE 23505 (unique_violation), as Laravel checks it.
override
listen(String channel) → Stream<String>
Payloads notified on channel, from a connection of its own (a pooled one would drop the subscription); closed when the listener cancels.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
select(String sql, [List<Object?> bindings = const []]) → Future<List<Map<String, Object?>>>
Runs a query and returns the rows as column → value maps.
override
toString() → String
A string representation of this object.
inherited
transaction<T>(Future<T> body(QueryExecutor tx)) → Future<T>
Runs body inside a transaction; rolls back when it throws.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

isRetryable(Object error) → bool
Whether error is a deadlock / serialization failure.
timeoutOption(Object? value, Duration fallback) → Duration?
A timeout option in seconds (DB_QUERY_TIMEOUT, DB_CONNECT_TIMEOUT): unset means fallback, 0 means none (null).

Constants

noTimeout → const Duration
What DB_QUERY_TIMEOUT=0 means for a driver whose timeout cannot be absent: longer than any deployment.
retryableCodes → const Set<String>
SQLSTATE codes that make a transaction worth retrying.