What is the difference between github.com/jinzhu/gorm and gorm.io/gorm?

Viewed 2393

I am using Go for application development, and I use the gorm library to connect to the database. I see gorm has 2 libraries github.com/jinzhu/gorm and gorm.io/gorm.

I don't know which one to use. How do they differ?

3 Answers

Gorm version 1 up to v1.9.16 was kept at github.com/jinzhu/gorm and to import it from your code you would use that path:

import (
    ...
    "github.com/jinzhu/gorm"
)

Go convention is that when a new package version is no longer backwards compatible, the import path should change, so when putting out version 2 the team decided to move the repo to a new organisation on github: https://github.com/go-gorm/gorm, and this new version gets imported into your code using gorm.io/gorm:

import (
    ...
    "gorm.io/gorm"
)

(bear in mind that due to quirks in the go ecosystem, v2 is kept tagged as >= v1.20.0, confusing I know!)

Gorm v2 is generally quite close to v1 in syntax and function, but more powerful, consistent and has had a large number of bugs squashed out. I haven't seen benchmarks but from the box it should also be more performant due to using prepared statements.

All in all, there is no reason not to use v2 in a new project, and plenty of reasons to migrate away from v1 in existing ones.

Actually it's a same repo but jinzhu move GormV2 to new repo(https://github.com/go-gorm/gorm or gorm.io/gorm). From my point of view, we should use update lib github.com/go-gorm/gorm

I suggest not to use github.com/jinzhu/gorm. Use gorm.io/gorm, because of my experience when using the old version sometimes an error appears

Related