Forge

Introduction

A small, explicit, dependency-light data-access library for Go.

GitHub

dbswitch is a data-access library for Go. You describe tables and run CRUD in plain Go — dbswitch talks to the configured database for you. No struct-tag reflection, no query-DSL magic: for SQL backends the generated SQL is transparent and always parameterized.

v0.5.0 supports PostgreSQL, MongoDB, and DynamoDB. All three back a common dbswitch.Store interface, so the same CRUD code runs against any of them. MySQL is planned — see the Roadmap.

Why dbswitch

  • 🧩 Explicit, not magic — describe tables as Go values; behaviour is predictable.
  • 🔒 Always parameterized — for SQL backends, every value is bound, never interpolated.
  • 🪶 Dependency-light core — the dbswitch package pulls in no third-party packages. Each backend lives in its own sub-package, so you only import the driver you use.
  • 🔁 Swappable backends — a shared Store interface means the same table/CRUD code targets PostgreSQL, MongoDB, or DynamoDB.
  • 🎯 Shared error values — native driver errors are translated to ErrNotFound / ErrDuplicate (with the constraint name), so your domain code doesn't depend on a specific driver — the same errors.Is checks work on every backend.
  • 📄 Sorted, paginated readsList adds sort, limit, and both keyset-cursor and offset pagination on top of the same equality filters; Count gives you a row count for the same filters.

At a glance

db, _ := postgres.Open(ctx, os.Getenv("DATABASE_URL"))
defer db.Close()

_ = db.Insert(ctx, "users", map[string]any{"email": "a@b.com"})
row, _ := db.FindOne(ctx, "users", map[string]any{"email": "a@b.com"})

Continue to Installation, or jump to the Quick start.

dbswitch is intentionally small. Before adopting it, read the Limitations — it deliberately does not cover rich queries, joins, migrations, or transactions.

On this page