Skip to content

Return the sealed dal.DB from NewDatabase - #162

Merged
trakhimenok merged 1 commit into
mainfrom
feat/sealed-dal-db
Jul 25, 2026
Merged

Return the sealed dal.DB from NewDatabase#162
trakhimenok merged 1 commit into
mainfrom
feat/sealed-dal-db

Conversation

@trakhimenok

Copy link
Copy Markdown
Contributor

Summary

  • Bumps github.com/dal-go/dalgo to v0.64.2, which renames today's dal.DB to dal.Backend and seals dal.DB so only dal.NewDB can produce one — every read-write transaction it starts now runs the framework's BeforeSave validation and hooks before this adapter's code is entered.
  • NewDatabase's single return statement changes from &database{...} to dal.NewDB(&database{...}); the package's var _ dal.DB = (*database)(nil) assertion becomes var _ dal.Backend = (*database)(nil) (a duplicate of that same assertion is dropped in the same edit).
  • dalgo2sql validates nothing itself today (confirmed: zero Validate references anywhere in the repo, tests included), so this is a pure addition, not a behaviour change.
  • Fixes ~29 whitebox test call sites that type-asserted NewDatabase's return value straight to the concrete *database (to reach adapter methods like Insert, Update, onlyReadWriteTx, ... that are not part of dal.DB). Recovers the concrete backend at each with dal.BackendOf — the escape hatch the framework added for exactly this.
  • Fixes TestTransaction/Upsert, which asserted an adapter-specific capability (Upsert, not part of any dal package interface) on the transaction handed into a RunReadwriteTransaction worker. The framework's validated transaction wrapper doesn't promote adapter-specific extras, so this needed the same dal.BackendOf unwrap one level up, before opening the transaction.
  • Adds TestConformance, wiring the new dalgotest.RunConformance suite against a real in-memory SQLite database (the same modernc.org/sqlite driver already used by sql_map_get_test.go) — no external database or env-gate needed. All 16 checks pass.

This is the adapter dalgo2mysql, dalgo2postgres, and dalgo2sqlite all wrap, so landing it first gives all three the validation pipeline for free.

Test plan

  • gofmt -l . — clean
  • GOWORK=off go vet ./... — clean
  • GOWORK=off go test -race -count=1 ./... — pass (includes TestConformance, genuinely executed, not skipped)
  • end2end/ submodule (separate go.mod, bumped the same way): GOWORK=off go test -race -count=1 ./... — pass, using the CGo mattn/go-sqlite3 driver against a real file-backed SQLite DB, all CRUD subtests ran (none skipped)

🤖 Generated with Claude Code

https://claude.ai/code/session_01SkkrXdtf8mU2GRo2hHsHT1

dalgo v0.64.2 renames today's dal.DB to dal.Backend and seals dal.DB so
only dal.NewDB can produce one, gaining the framework's BeforeSave
validation and hook pipeline on every read-write transaction. Bump the
dependency and change NewDatabase's single return statement to
dal.NewDB(&database{...}), and update the package's var _ dal.DB
assertion to dal.Backend (a duplicate of that assertion is dropped in
the same edit).

dalgo2sql validates nothing itself today, so the framework's pipeline
is a pure addition rather than a change in behaviour, and every
existing check keeps passing unmodified.

Sealing dal.DB does ripple through the test suite, though: many
whitebox tests type-assert NewDatabase's return value straight to the
concrete *database so they can call adapter methods (Insert, Update,
Delete, onlyReadWriteTx, ...) that are not part of dal.DB. That
assertion now fails because the returned value is dal.NewDB's wrapper
struct, not *database. Recover the concrete backend at each of those
call sites with dal.BackendOf, exactly the escape hatch the framework
added for this. One of these, TestTransaction/Upsert, needed the same
fix a step earlier: it asserts a capability (Upsert) that is specific
to this adapter and not part of any dal package interface, so the
framework's validated transaction wrapper does not promote it either;
unwrapping via dal.BackendOf before opening the transaction restores
the adapter's own transaction type the assertion expects.

Add TestConformance, wiring the new dalgotest.RunConformance suite
against a real in-memory SQLite database via the same
modernc.org/sqlite driver already used elsewhere in this package's
tests, so it needs no external database or env-gate and genuinely
proves the framework validates writes before this adapter is entered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SkkrXdtf8mU2GRo2hHsHT1
Signed-off-by: Alexander Trakhimenok <alex@trakhimenok.com>
@trakhimenok
trakhimenok merged commit ec8330a into main Jul 25, 2026
4 checks passed
@trakhimenok
trakhimenok deleted the feat/sealed-dal-db branch July 25, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant