dargres 4.0.0
dargres: ^4.0.0 copied to clipboard
Dargres is a pure-Dart PostgreSQL driver based on Python pg8000
Changelog #
4.0.0 #
Added #
- Added direct extended-protocol APIs on connection, transaction, and pool
surfaces:
queryMapsreturns one stableMap<String, dynamic>per row without an intermediateRowor stream event.queryTyped<T>maps a reused, ephemeralRowViewdirectly to application entities.queryEachconsumes rows through a synchronous callback without retaining a driver result list.queryCachedkeeps the compatibleResults/Rowresult shape while using the direct decoder and statement cache.
- Added
RowViewtyped accessors andResultSchemawith decoders resolved once per result column. - Added a bounded per-physical-connection LRU prepared-statement cache for the
direct APIs.
statementCacheCapacityis available onCoreConnectionandConnectionSettings, defaults to64, and uses0to disable retention. Cache length and hit/miss/eviction counters are exposed for diagnostics. - Added selective binary result decoding for supported scalar OIDs, with text fallback for unsupported columns. Parameters remain text-encoded.
- Added opt-in
requireBinaryResultsto the four direct APIs on connections, transactions, and pools. It requests binary for every result column and fails on an unsupported OID; strict failures never retry the SQL and cannot duplicate side effects. The safe selective/text-fallback mode remains the default. - Added internal MD5, SHA-1, SHA-256, HMAC, PBKDF2, hexadecimal, Windows-1252 and bounded FIFO pool implementations, leaving zero runtime package dependencies.
- Added opt-in named IANA timezone decoding with full-history and compact generated databases. UTC remains the allocation-minimal default.
- Added separate
test/unitandtest/integrationsuites and PostgreSQL 17 CI usinglocalhost:5432, databasepostgres, anddart/dartcredentials. - Added a reproducible JIT/AOT comparison harness and a configurable connection/pool soak tool with throughput, queue, connection, error, and RSS reporting.
- Added
ReconnectPolicywith bounded exponential backoff and jitter, plus explicitping()/checkHealth()APIs. - Added a configurable command timeout, PostgreSQL wire-level
CancelRequest, configurable cancellation grace period, andcancelCurrentQuery()for direct connections. - Added a bounded pool admission queue (
maxPendingOperations),PoolQueueFullException, and rejection/timeout/replacement metrics. - Added the pure-Dart IANA generator under
scripts/and a Windows PostgreSQL restart fault test usinggsudo. - Validated the release with 326 unit tests, 71 PostgreSQL integration tests, a real three-second PostgreSQL service outage/recovery, and a 60-second soak of 1,346,073 operations with zero errors.
Changed #
- By default, cold direct queries use one
Parse + Describe + Bind + Execute + Syncprotocol batch and text results. Warm cache hits reuse statement/schema metadata, sendBind + Execute + Sync, and request binary per supported result column. Opt-in strict mode requests binary for every column on both paths. - Data rows are decoded directly from byte ranges. The typed/callback paths reuse one value buffer, while the map and compatibility paths materialize only their documented final result objects.
- Prepared-statement executions now use independent per-execution state rather
than reusing a stream controller, counters, and errors from the prepared
Queryhandle. Rowis nowListBase<Object?>; indexed values andtoList()are explicitly nullable-object typed.- Enabling
tcpKeepalivenow applies the socket keepalive option. PostgreSqlPoolnow leases a distinct physical connection for an entire operation/transaction and replaces sockets closed by timeouts.- Concurrent
connect()and reconnect calls now coalesce through authentication; terminalclose()invalidates pending opens so an older socket cannot resurrect the connection. - A pool timeout now quarantines its lease until the underlying Future settles, then replaces the socket in the same slot before reuse.
- Cached date/timestamp decoders now observe
SET TIME ZONEchanges without rebuilding the prepared-statement schema. - Authentication
ErrorResponseparsing now tolerates diagnostics received beforeclient_encodingis applied and always completes a failed connect. - SCRAM now requires a configured password, selects the supported
SCRAM-SHA-256mechanism explicitly, and reports configuration errors without leaking a null-check or a second uncaught Zone error. - Removed unawaited
Socket.flush()calls from startup, SCRAM, and normal query writes. They could race the nextSocket.add()and intermittently raiseStreamSink is bound to a stream; the terminal flush is awaited. - The minimum Dart SDK is now
^3.6.0.
Removed #
- Removed the direct runtime dependencies on
crypto,convert,collection,enough_convert,pool, andpath. - Removed the Terrier/ISOOS/queue buffers, pack/unpack alternatives, experiments, commented pool implementation, unused executor/retry/stack-trace copies, dead converters/utilities and obsolete benchmark scripts.
- Removed the old uninitialized timezone branch; named-zone behavior is now the explicit generated-IANA path.
- Removed
PostgreSqlPool.restartOnTimeoutand transactiontimeoutInner; both allowed unsafe or ambiguous timeout ownership.
Breaking changes and migration notes #
Row.operator []now returnsObject?instead ofdynamic. Existing code may need an explicit cast, for examplerow[0] as int.- Parameters on the four direct query APIs are now named. They accept explicit
PostgreSQL
$n, question-mark, colon and at-sign placeholder styles;?is never auto-detected. UseListfor$n/?,Mapfor:/@, and retain the default$nstyle when SQL contains PostgreSQL JSON?operators. - A
RowViewand itsvalueslist are valid only inside the synchronous mapper/callback. Copy data or construct an owned entity before returning; do not retain the view. queryEachdoes not await asynchronous callbacks.- A prepared
Queryis statement metadata, not the observable state of its most recent execution. Read rows, affected counts, and errors from the returnedResults/ResultStreaminstead. QueryState/Query.statewere removed because no protocol decision consumed them.PostgreSqlPoolno longer implementsConnectionInterface; connection-like methods that threwUnimplementedErroror leaked prepared handles outside a lease were removed. UserunInTransactionand the materialized/direct query APIs.queryCachedcaches prepared-statement metadata, never result rows. The cache is local to a physical connection, so pooled connections warm independently.- Direct command timeouts are opt-in so the default hot path does not allocate
a Dart
Timerfor every query. CoreConnection.close()is terminal. Create a new connection object after an intentional close; automatic reconnect remains available only after a recoverable socket failure.- Pool overload above
maxPendingOperationsis rejected instead of queued indefinitely.
See PERFORMANCE_MIGRATION.md for before/after examples and cache lifecycle
guidance. In the recorded 10,000-row run, dargres beat the pinned
postgres_fork in all six measured scenarios after lifecycle hardening:
2.13x-2.75x on JIT and 2.02x-2.66x on AOT. Raw reports are under
benchmark/driver_comparison/results/.
3.1.2 #
- Fixed the default
Locationinitialization to use UTC.
3.1.1 #
- Added flags to
TimeZoneSettingsfor more flexible decoding ofdate,timestamp, andtimestamptzvalues.
3.1.0 #
- Breaking change: decoded
timestamp without time zoneas a localDateTimeand decodedtimestamp with time zoneusing the timezone defined on the connection.
3.0.2 #
- Fixed setting
application_nameon PostgreSQL versions earlier than 8.2.
3.0.1 #
- Fixed a critical stack-overflow bug introduced in 3.0.0. Timeout parameters
were removed from query execution methods such as
queryNamed,queryUnnamed,querySimple,execute,prepareStatement, andexecuteStatement.
3.0.0 #
- Implemented
PostgreSqlPoolwith optional automatic reconnect after a connection drop.
final settings = ConnectionSettings(
user: 'user',
database: 'database',
host: 'localhost',
port: 5433,
password: 'password',
textCharset: 'latin1',
applicationName: 'dargres',
);
final conn = PostgreSqlPool(
2,
settings,
allowAttemptToReconnect: true,
);
2.2.4 #
- Added Windows-1252 (
win1252) support toCoreConnection.
final con = CoreConnection(
'user',
database: 'db',
host: 'localhost',
port: 5432,
password: 'pass',
textCharset: 'win1252',
);
2.2.3 #
- Fixed a serious intermittent error when executing prepared statements for
SELECTqueries that return large amounts of data.
2.2.2 #
- Fixed query-error and database-restart handling bugs.
2.2.1 #
- Fixed bugs in
queryUnnamedandprepareStatement.
2.2.0 #
- Implemented
ResultStreamandResultsfor data returned byqueryUnnamedandquerySimple.
2.1.0 #
- Added placeholder-style selection to
queryUnnamedandprepareStatement, including PHP PDO-style question-mark parameters.
queryUnnamed(
'SELECT * FROM book WHERE title = ? AND code = ?',
['title', 10],
placeholderIdentifier: PlaceholderIdentifier.onlyQuestionMark,
);
2.0.0 #
- Migrated the package to null safety.
1.0.1 #
- Fixed an insert bug and implemented
queryUnnamedfor unnamed prepared statement execution.
1.0.0 #
- Initial version.