Skip to Content
fusion-orm
Core Concepts

Config reference

Every Config field — types, defaults, and when to reach for it.

Config holds session-wide settings. It is copied (shallowly) whenever a session derivative is made, so session flags never leak back to the root — Session, WithContext, Debug, and DryRun on a derivative leave the root config untouched.

// Config holds session-wide settings. It is copied (shallowly) whenever a
// session derivative is made, so session flags never leak back to the root.

All fields

Prop

Type

Four fields you never set yourself: Dialector is filled by Open, and tables, callbacks, joinTables (unexported caches — schema parsing, CRUD processors, join-table overrides) are initialized inside Open and shared by every derivative.

Notes on the dials that surprise people

  • AllowGlobalUpdate defaults to off, and the guard is deliberate: an Update or Delete without a WHERE clause fails with fusion.ErrMissingWhereClause until you set it (or add conditions).
  • PrepareStmt is off by default. When on, every statement goes through an LRU+TTL cache that recovers from driver.ErrBadConn purges; tune the bounds with PreparedStmtCacheSize (default 1000) and PreparedStmtTTL (0 = never expires).
  • TranslateError requires the dialector to implement ErrorTranslator — both shipped dialects do. If yours doesn't, Open warns rather than silently dropping translation.
  • SkipDefaultTransaction trades the implicit per-write transaction for speed. Turn it off only when you understand the multi-statement write windows you create.

Example

db, err := fusion.Open(sqlite.Open("app.db"), &fusion.Config{
	TranslateError:        true,
	PrepareStmt:           true,
	PreparedStmtCacheSize: 500,
	StrictTags:            true,
	FullSaveAssociations:  true,
})

*Config implements Option, so it can be passed straight to Open. The config is then frozen for the root; per-call overrides go through Session, not by mutating the root.

Copying is shallow — that's the point

The copy shares the immutable parts (pool, dialect, caches) by design; only the flag fields are per-session. Never write to a Config field after Open — pass overrides via Session instead.

Next

On this page