PostgreSQLConnection class

Instances of this class connect to and communicate with a PostgreSQL database.

The primary type of this library, a connection is responsible for connecting to databases and executing queries. A connection may be opened with open after it is created.

Implemented types
Available extensions

Constructors

PostgreSQLConnection(String host, int port, String databaseName, {Encoding encoding = utf8, String? username, String? password, int timeoutInSeconds = 30, int queryTimeoutInSeconds = 30, Object timeZone = 'UTC', bool useSSL = false, bool isUnixSocket = false, bool allowClearTextPassword = false, ReplicationMode replicationMode = ReplicationMode.none, DecodingSettings decodingSettings = const DecodingSettings(), String? applicationName, Map<String, String> startupParameters = const {}, PgSslMode? sslMode, SecurityContext? securityContext, bool cancelQueryOnTimeout = false, int? maxPreparedStatements})
Creates an instance of PostgreSQLConnection.

Properties

allowClearTextPassword → bool
If true, allows password in clear text for authentication.
final
applicationName → String?
The application_name sent in the startup message, if any.
final
cancelQueryOnTimeout → bool
When true, a query that exceeds its timeout is also cancelled on the server with a CancelRequest (see cancelQuery). Otherwise (default) only the client stops waiting and the server keeps running the query.
final
databaseName → String
Name of database this connection refers to.
final
decodingSettings → DecodingSettings
How some types (interval, time, timetz, inet and cidr) are decoded.
final
effectiveSslMode → PgSslMode
The SSL mode actually used by this connection.
no setter
encoding → Encoding
dataBase charset
final
hashCode → int
The hash code for this object.
no setterinherited
host → String
Hostname of database this connection refers to.
final
isClosed → bool
Reports on the latest known status of the connection: whether it was open or failed for some reason.
no setter
isUnixSocket → bool
If true, connection is made via unix socket.
final
messages → Stream<ServerMessage>
Stream of server messages
no setter
notifications → Stream<Notification>
Stream of notification from the database.
no setter
password → String?
Password for authenticating this connection.
final
port → int
Port of database this connection refers to.
final
processID → int
The processID of this backend.
no setter
queryTimeoutInSeconds → int
The default timeout for PostgreSQLExecutionContext's execute and query methods.
final
queueSize → int
Returns this context queue size
no setterinherited
replicationMode → ReplicationMode
The replication mode for connecting in streaming replication mode.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
securityContext → SecurityContext?
The trusted CAs and the client certificate of the TLS handshake; null uses the system roots.
final
settings → Map<String, String>
Settings values from the connected database.
final
socket → Socket?
no setter
sslMode → PgSslMode?
SSL mode. When null, useSSL decides: PgSslMode.require when true, PgSslMode.disable when false.
final
startupParameters → Map<String, String>
Additional session parameters sent in the startup message.
final
timeoutInSeconds → int
The amount of time this connection will wait during connecting before giving up.
final
timeZone ↔ TimeZoneSettings
The timeZone of this connection for date operations that don't specify a timeZone.
getter/setter pair
username → String?
Username for authenticating this connection.
final
useSSL → bool
Whether or not this connection should connect securely.
final

Methods

addMessage(ClientMessage message) → void
Adds a Client Message to the existing connection
cancelQuery() → Future<void>
Cancela, no servidor, a consulta em execução nesta conexão (envia um CancelRequest por uma conexão separada, como o libpq).
cancelTransaction({String? reason}) → void
Cancels a transaction on this context.
override
close() → Future
Closes a connection.
copyFrom(String sql, Stream<List<int>> data, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>
Executa um COPY ... FROM STDIN enviando data (no formato indicado no próprio comando: texto, CSV ou binário) e devolve o número de linhas copiadas.
inherited
copyFrom(String sql, Stream<List<int>> data, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

copyRows(String table, List<String> columns, Iterable<List<Object?>> rows, {String? schema, int? timeoutInSeconds}) → Future<int>
Insere rows em table com COPY ... FROM STDIN (formato texto), muito mais rápido que INSERTs para muitas linhas. Devolve o número de linhas inseridas.
inherited
copyRows(String table, List<String> columns, Iterable<List<Object?>> rows, {String? schema, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

copyTo(String sql, void onData(Uint8List data), {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>
Executa um COPY ... TO STDOUT, entregando a onData o conteúdo de cada mensagem de dados (no formato texto, uma linha por chamada; veja PgCopy.decodeTextRow), e devolve o número de linhas copiadas.
inherited
copyTo(String sql, void onData(Uint8List data), {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

execute(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<int>
Executes a query on this context.
inherited
listen(String channel) → Future<void>
Passa a receber notificações do canal channel (LISTEN). As notificações chegam em notifications (ou notificationsFor).
mappedResultsQuery(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, bool? allowReuse, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<List<Map<String, Map<String, dynamic>>>>
Executes a query on this connection and returns each row as a Map.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notificationsFor(String channel) → Stream<Notification>
Notificações recebidas apenas do canal channel.
notify(String channel, [String? payload]) → Future<void>
Envia uma notificação para channel (pg_notify).
open() → Future
Establishes a connection with a PostgreSQL database.
query(String fmtString, {dynamic substitutionValues, bool? allowReuse, int? timeoutInSeconds, bool? useSimpleQueryProtocol, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<PostgreSQLResult>
Break change
inherited
queryAsMap(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, bool? allowReuse, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<List<Map<String, dynamic>>>
Executes a query on this connection and returns each row as a Map.
inherited
queryStream(String fmtString, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int fetchSize = 1000, int? timeoutInSeconds}) → Stream<PostgreSQLResultRow>
Executa fmtString (um SELECT, VALUES ou TABLE) com um cursor no servidor e entrega as linhas aos poucos, em lotes de fetchSize (DECLARE ... CURSOR e FETCH).
inherited
queryStream(String fmtString, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int fetchSize = 1000, int? timeoutInSeconds}) → Stream<PostgreSQLResultRow>

Available on PostgreSQLExecutionContext, provided by the PgQueryStreamExecutionContext extension

savepoint<T>(Future<T> block(PostgreSQLExecutionContext ctx)) → Future<T>

Available on PostgreSQLExecutionContext, provided by the PgSavepointExecutionContext extension

Executa block dentro de um SAVEPOINT da transação atual.
toString() → String
A string representation of this object.
inherited
transaction(Future queryBlock(PostgreSQLExecutionContext connection), {int? commitTimeoutInSeconds}) → Future
Executes a series of queries inside a transaction on this connection.
unlisten([String? channel]) → Future<void>
Deixa de receber notificações de channel, ou de todos os canais se channel for omitido (UNLISTEN).

Operators

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