Skip to Content
fusion-orm

What is fusion-orm?

A Go ORM that pairs a SQL-first query engine with a fluent chaining API, a callback pipeline, and first-class generics.

fusion-orm is a Go ORM built on database/sql. It pairs bun's SQL-first query engine — zero-allocation byte-slice builders, dialect feature flags, precompiled field closures, cached schema reflection — with gorm's fluent chaining and callback pipeline: copy-on-write sessions, a clause registry, sentinel errors, and a generics facade.

db, err := fusion.Open(sqlite.Open("app.db"))

user := User{Name: "Ada"}
db.Create(&user)

var got User
db.Model(&User{}).Where("name = ?", "Ada").First(&got)

Every chainable method returns a derivative *DB; nothing mutates the receiver. Every finisher reports through exactly two fields — Error and RowsAffected — and every branchable failure is an errors.Is-compatible sentinel.

The mental model

A query moves through four layers, and the docs follow the same path:

  1. Chain — Where, Order, Preload, … accumulate clauses on a per-chain Statement (copy-on-write).
  2. Finish — Create, Find, Delete, … trigger a callback processor.
  3. Build — the processor renders registered clauses into a reused []byte through per-dialect appenders.
  4. Execute — the statement runs through database/sql (or the prepared statement cache), and rows scan back through compiled per-field closures.

Because SQL is built as bytes and rendered by the dialect, you can always ask what will run: ToSQL interpolates a chain into a string, DryRun captures SQL and vars without executing, and the logger traces every statement.

Feature highlights

  • Query first — chainable Where/Or/Order/Limit/Offset/Select/Distinct, struct and map conditions, Scopes, raw Clauses, stable ToSQL.
  • CRUD parity — Create/Save/Updates/Delete/First/Take/Last/Find, FindInBatches, FirstOrInit/FirstOrCreate, Pluck, Row/Rows/Scan.
  • Relations — batched nested Preload, inline Joins, an Association API, and association callbacks for has-one, has-many, belongs-to, many-to-many, and polymorphic relations.
  • Generics — fusion.G[T] with checked chain and finisher interfaces.
  • Soft delete — embed fusion.DeletedAt; Unscoped and Restore.
  • Prepared statements — optional LRU+TTL cache with ErrBadConn recovery.
  • Error translation — driver constraint errors map onto sentinels.
  • Migrations — AutoMigrate plus versioned Go and numbered SQL migrations guarded by a lock table.
  • Observability — QueryHook wrappers, SlogQueryHook, slog logger adapter, slow-query tracing.

Dialects

SQLite (pure Go, modernc.org/sqlite) and PostgreSQL (pgx/v5) ship in-tree. Dialects declare capabilities as a feature bitset — query builders branch on capability, never on dialect-name strings.

Where next

On this page