Introduction
A small, explicit, dependency-light data-access library for Go.
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
dbswitchpackage 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
Storeinterface 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 sameerrors.Ischecks work on every backend. - 📄 Sorted, paginated reads —
Listadds sort, limit, and both keyset-cursor and offset pagination on top of the same equality filters;Countgives 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.