Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.45 KB

File metadata and controls

57 lines (39 loc) · 1.45 KB

dbsnap

Automatic database row snapshots before DML execution. A transaction-like rollback mechanism for PostgreSQL testing and debugging.

How It Works

dbsnap runs as a wire protocol proxy between your application and PostgreSQL. It transparently intercepts DML queries (INSERT, UPDATE, DELETE), snapshots affected rows, and provides undo capability through a terminal UI.

Your App (:5433) → dbsnap (proxy) → PostgreSQL (:5432)

Undo Logic

Original Query Undo Action
INSERT Deletes the inserted rows
UPDATE Restores rows to their previous values
DELETE Re-inserts the deleted rows

Usage

# Start dbsnap proxy + TUI (defaults to localhost:5432)
dbsnap

# Or specify a custom PostgreSQL address
dbsnap --pg myhost:5432

# Custom proxy listen port
dbsnap --listen :5433 --pg myhost:5432

# Point your app at the proxy instead of PostgreSQL directly
DATABASE_URL="postgres://user:pass@localhost:5433/mydb"

The proxy automatically detects the user and database from the client's connection — no need to specify a full connection string.

Keybindings

Key Action
↑/↓ Navigate history
u Undo selected query
tab Switch panels
q Quit

Tech Stack

  • Go — core language
  • Bubble Tea — terminal UI framework
  • pg_query_go — PostgreSQL SQL parser
  • pgx — PostgreSQL driver

License

MIT