aws / aws/aws-advanced-go-wrapper

Support for bun (uptrace/bun) PostgreSQL driver

Open
#428 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
78
Forks
12
Avg merge
3d 20h
Merged PRs (30d)
13

Description

## Feature Request

Add support for [bun](https://github.com/uptrace/bun)'s PostgreSQL driver (`uptrace/bun/driver/pgdriver`) alongside the existing pgx and mysql drivers.

bun is a widely-used Go ORM/query builder (4.7k GitHub stars) that uses its own `database/sql`-compatible PostgreSQL wire protocol implementation (not pgx). Paxos uses it in production for Aurora PostgreSQL workloads that would benefit from the wrapper's failover, EFM, and IAM plugins.

## Current Blocker

The wrapper can't be used with bun today because `DialectManager.GetDialect()` hardcodes a check for the `awssql-pgx` driver name for all PostgreSQL connections:

```go
// dialect_manager.go
if strings.Contains(driverProtocol, "postgres") {
driverIsRegistered := d.FindRegisteredDriver(AWS_PGX_DRIVER_CODE)
if !driverIsRegistered {
return nil, error_util.NewGenericAwsWrapperError(...)
}
```

A custom `DriverDialect` implementation for bun registers under its own driver name (e.g. `awssql-bunpg`), but the dialect manager rejects it because `awssql-pgx` isn't registered. This blocks bun users from enabling failover, EFM, or any plugin that goes through dialect detection — even though the `DriverDialect` interface is public and fully implemented.

The same issue would affect anyone implementing a custom `DriverDialect` for another PostgreSQL driver (e.g., lib/pq).

## Proposal

Two approaches (not mutually exclusive):

### 1. Remove the hardcoded driver registration check

The `FindRegisteredDriver(AWS_PGX_DRIVER_CODE)` check in `GetDialect()` is redundant — if no driver is registered, the connection fails with a clear error at `sql.Open` / `Ping` time. Removing it unblocks custom `DriverDialect` implementations immediately. This is a small change (~20 lines removed).

We have a PR ready for this if you'd like to review it.

### 2. Add an official `bun-driver` module

Similar to the existing `pgx-driver/` and `mysql-driver/` modules, add a `bun-driver/` module that provides:

- `BunPgDriverDialect` — implements `DriverDialect` for bun's pgdriver (URL-format DSN, bun-specific error types)
- `BunPgErrorHandler` — error classification using `pgdriver.Error` (same SQLSTATE codes as pgx)
- `BunPgRowParser` — type assertions for bun's `driver.Value` types (identical to pgx — same wire protocol)
- `BunPgPropertyResolver` — DSN parameter mapping (identical to pgx — same PostgreSQL parameters)
- Driver registration via `init()` as `awssql-bunpg`

We've prototyped this at Paxos (a few hundred lines, mostly parallel to the pgx-driver module) and can contribute it as a PR. The main bun-specific difference is DSN format: bun requires URL-format (`postgres://user@host:port/db?params`) while pgx uses key=value format.

## Workaround

Our current workaround is registering a dummy driver under the `awssql-pgx` name to satisfy the check, which works but is hacky.

Contributor guide

Open the contributing guide

Research direction

Start with dialect_manager.go and GetDialect(), then compare the existing pgx-driver/ and mysql-driver/ modules with the public DriverDialect interface. Clarify whether the driver-registration change, an official bun-driver/ module, or both are in scope; done means bun's PostgreSQL driver works with dialect detection and the wrapper plugins.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, go, postgresql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.