Skip to Content
fusion-orm
Guides

Migrating from GORM

Tag aliases, API parity, behavior differences, and config mapping for moving a gorm codebase onto fusion-orm.

fusion-orm is written for gorm users: the chainable names, finisher names, sentinel errors, and base models are the same, struct tags parse gorm syntax directly, and Config carries the same knobs. This page covers what maps 1:1, what differs in behavior, and what is genuinely missing.

Tag mapping

The parser accepts gorm's ; separator as well as ,, and aliases gorm's key names onto fusion's keys (schema/tag.go:72-74):

// gormTagAliases documents the 1:1 migration from gorm:"..." keys.
gorm tagfusion tagNotes
primaryKeypkAliased (schema/tag.go:55)
autoIncrementautoincrementAliased (schema/tag.go:56)
not nullnotnullSpace is stripped during key normalization (schema/tag.go:38-40)
uniqueIndexuniqueAliased (schema/tag.go:58)
embeddedembedAliased (schema/tag.go:59)
size:Ntype:...Maps onto type with the value passed through (schema/tag.go:69); prefer an explicit type:varchar(N)
column:NAMEcolumn:NAMESame
type:SQLtype:SQLSame
notnullnotnullSame
default:VALUEdefault:VALUESame
index[:NAME]index[:NAME]Same
unique[:NAME]unique[:NAME]Same
-, ->, <--, ->, <-Same semantics
serializer:jsonserializer:json (or bare json)Both enable JSON marshaling (schema/field.go:209)
foreignKey:FIELDforeignKey:FIELDSame
references:FIELDreferences:FIELDSame
many2many:TABLEmany2many:TABLESame
polymorphic[:VALUE]polymorphic[:VALUE]Same

The parser's own test case is a complete gorm tag migrating unchanged (schema/tag_test.go:20):

{"gorm semicolon migration", "column:user_email;primaryKey;autoIncrement;not null;uniqueIndex;foreignKey:UserID", "", map[string]string{
	"column": "user_email", "pk": "", "autoincrement": "", "notnull": "",
	"unique": "", "foreignkey": "UserID",
}},

You can leave most tags exactly as they are. The one structural change: fusion tags are spelled fusion:"...".

Unknown keys

Unknown key:value keys warn through the logger by default; set Config.StrictTags to fail the parse with schema.ErrInvalidTag instead (schema/tag.go:100-106).

API parity

Same names, same signatures where the semantics allow:

db, err := gorm.Open(sqlite.Open("app.db"), &gorm.Config{})

tx := db.Model(&User{}).Where("name = ?", "Ada").First(&user)
db.Create(&user)
db.Save(&user)
db.Model(&User{}).Updates(map[string]any{"age": 31})
db.Delete(&user, user.ID)
gormfusionSame?
gorm.DBfusion.DBSession handle; copy-on-write chaining in both
gorm.Open(dialector, &gorm.Config{})fusion.Open(dialector, &fusion.Config{})Same shape
gorm.Modelfusion.ModelID/CreatedAt/UpdatedAt/DeletedAt (model_base.go:15-20)
gorm.DeletedAtfusion.DeletedAtTime/Valid, Valuer/Scanner (soft_delete.go:18-21)
gorm.G[T]fusion.G[T]Checked chain + finisher interfaces (generics.go:11-58)
Chainables: Model, Where, Or, Order, Limit, Offset, Select, Distinct, Joins, Preload, Scopes, Clauses, Unscoped, Session, WithContext, Debug, Attrs, Assign, FirstOrInit, FirstOrCreate, Count, PluckSame namesSame receiver semantics
Finishers: Create, Save, Find, First, Take, Last, Update, Updates, Delete, FindInBatches, Row, Rows, Scan, ExecSame namesSame
UpdateColumn/UpdateColumnsSameSkip hooks and timestamps in both
ErrRecordNotFoundSame sentinel value, errors.Is-compatible (errors.go:21-23)Yes

Behavior differences

These are the deliberate deviations. Read them before trusting muscle memory.

No Group() or Having()

fusion-orm does not implement Group() or Having() chainable methods — there is no clause.Group builder and no GROUP BY slot in the build order. Global aggregates work through a raw Select plus Scan:

var total int64
if err := db.Model(&crudUser{}).Select(`COUNT(*) AS total`).Scan(&total).Error; err != nil || total != 3 {
	t.Errorf("scalar Scan = %d, %v", total, err)
}
SELECT COUNT(*) AS total FROM "crud_users"

Per-group aggregation needs raw SQL via Exec/Rows/Scan until the clauses land. The full honest walkthrough lives in GROUP BY & HAVING.

Assign applies only when the record is NOT found

In gorm, Assign values are applied both on found and not-found paths of FirstOrInit/FirstOrCreate. In fusion-orm, Assign is applied only in the not-found branch of FirstOrInit (finisher_api.go:487-494) — a found record is returned untouched.

Save with a set primary key routes to Updates

Save on a record whose PK is set goes through Updates (finisher_api.go:72-77), and Updates with a struct writes non-zero fields only (finisher_api.go:271-278). Writing an explicit zero value needs a map:

if cond, vars, ok := pkCondition(table, values[0]); ok {
	return db.Where(cond, vars...).Updates(value)
}
// zero-value writes need Updates(map):
db.Model(&User{}).Where("id = ?", u.ID).Updates(map[string]any{"age": 0, "name": "x"})

Delete by a slice of primary keys is not supported

Delete conditions accept a string with args, a scalar id, or a struct / map condition — not a slice of ids (finisher_api.go:145-185). A slice lands in the default case and fails with ErrInvalidValue. There is no slice-expanding IN helper either — bound values are never rewritten into lists (statement.go:296-299). Loop the ids, or issue the statement per id:

for _, id := range ids {
	db.Delete(&User{}, id)
}

UpdateColumns behaves the same, not differently

UpdateColumn/UpdateColumns skip hooks and automatic timestamps, exactly like gorm (finisher_api.go:228-239):

// UpdateColumns is Updates without hooks or automatic timestamps.

Not yet in fusion-orm

gorm featureStatus in fusion-orm
DBResolver (read/write splitting)Not implemented
ShardingNot implemented
Hints (optimizer hints)Not implemented
Gen (code generation)Not implemented
Prometheus pluginNot implemented (observability is via QueryHook/SlogQueryHook)

Also absent by design

Group() / Having() are not yet implemented at all — anything showing them chained on a fusion.DB is wrong. Dialects shipped are SQLite and PostgreSQL only; MySQL and MSSQL are gorm's territory.

Config mapping

gorm.Config fields your code probably sets, and where they land:

db, err := gorm.Open(sqlite.Open("app.db"), &gorm.Config{
	Logger:               logger.Default.LogMode(logger.Warn),
	NowFunc:              func() time.Time { return time.Now().UTC() },
	DryRun:               false,
	AllowGlobalUpdate:    false,
	SkipDefaultTransaction: true,
	PrepareStmt:          true,
	TranslateError:       true,
	DisableAutomaticPing: false,
	NamingStrategy:       schema.NamingStrategy{},
	FullSaveAssociations: true,
})

All ten fields exist with the same meaning (fusion.go:52-102). Two fusion-specific additions worth setting on new code:

  • StrictTags — reject unknown tag keys at parse time instead of warning (fusion.go:75-76).
  • PreparedStmtCacheSize / PreparedStmtTTL — bound and expire the prepared-statement cache that PrepareStmt enables (fusion.go:79-82).

Where next

On this page