In the Go language world, Beego ORM, GORM, SQLX, GORP, XORM are the Go database frameworks with the most stars in Github that I know. These are the old database frameworks in the Go language world.

Beego ORM is beego’s own ORM framework library, and the number of stars is counted according to The number of Stars of Beego (beego also has a database framework beedB before beego, because Xie Da did not maintain this database in 2014, so it did not appear in my statistical list).

SQLX and XORM are the author’s favorite and most used Go database framework libraries in actual development. SQLX supports SQL template and mybatis SQL configuration. SQLX supports SQL template and mybatis SQL configuration. SQLX supports SQL template and mybatis SQL configuration. The second SQLT library enables SQLX to support primary and secondary data sources, read and write separation;

Xorm also has a custom enhanced version of Xormplus/XORm, which enables XORM to support SQL templates and SQL configuration like Mybatis, supports dynamic SQL, supports nested transactions, and supports transaction propagation mechanism similar to Spring in Java. And like XORM, it has built-in support for SQL Builder.

Finally, there is another interesting Go database framework library, Argen, which uses annotation method in the specific implementation, which is relatively rare in Go language development library. For the author, it is a library worth reading source code and learning, and it gives Go language another way of thinking.

In actual development, the author often chooses database framework library in SQLX, XORM and XORmplus/XORM based on business complexity and DATABASE SQL complexity. Most of the time, the author prefers XORmplus/XORM. If you also have a good Go language database framework recommendation, may wish to leave a message in the message area, we exchange and share.

The following is a list of Go language database frameworks that I have compiled. Some of the source code is very compact and concise (although there are not many stars, BUT I still list them), which is very suitable for learning to read and help yourself to improve the design and implementation of the Go language library.

Project Name Stars Forks Description
beego orm 12216 2814 A powerful ORM Framework for Go. (Beego built-in ORM)
gorm 6548 809 The fantastic ORM library for Golang, aims to be developer friendly
sqlx 3244 276 general purpose extensions to golang’s database/sql
gorp 2555 306 Go Relational Persistence – an ORM-ish library for Go
xorm 2273 341 Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle xorm.io
xo 1255 103 Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server
pg 1104 70 PostgreSQL ORM for Golang with focus on PostgreSQL features and performance
db 975 73 Productive data access layer for Go.
dbr 816 87 Additions to Go’s database/sql for super fast performance and convenience.
sqlboiler 755 64 Generate a Go ORM tailored to your database schema.
hood 659 51 Database agnostic ORM for Go
reform 546 19 A better ORM for Go, based on non-empty interfaces and code generation.
godb 498 15 A Go query builder and struct mapper.
qb 492 21 The database toolkit for go
qbs 460 88 QBS stands for Query By Struct. A Go ORM.
dat 459 37 Go Postgres Data Access Toolkit
go-kallax 443 26 Kallax is a PostgreSQL typesafe ORM for the Go language.
dotsql 308 19 A Golang library for using SQL.
xormplus/xorm 278 48 Simple and Powerful ORM for Go, support mysql, postgres, tidb, sqlite3, MSSQL, oracle (custom enhanced version)
jet 199 21 Jet is a super-flexible and lightweight SQL interface for Go
goyesql 179 9 Parse a file and associate SQL queries to a map. Useful for separating SQL from code logic.
ozzo-dbx 175 24 A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
genmai 144 17 Simple, better and easy-to-use ORM library for Golang
sqlt 143 23 like mybatis see README-zh.md
squalor 132 21 Go SQL utility library
argen 122 8 An ORM code-generation tool for Go, provides ActiveRecord-like functionality for your types.
sqalx 76 4 Nested transactions for sqlx
goSQL 64 1 a ORM like library in Go (golang) that makes SQL easier to use.
gomodel 55 7 A lightweight, fast, orm-like library helps interactive with database
vivom 53 1 a powerful Go ORM library
orm 45 11 golang ORM , mysql , sqllite3 , hash redis
ngorm 29 2 Neo GORM: The modern fork of gorm The fantastic ORM( Object Relational Mapper ) for Go
gatsby 22 1 Gatsby Database Toolkit For Go (ORM, SQL Builder and SQLUtils)
go-ormtools 20 1 A package with helper functions
orange 19 4 A lightweight Object Relational Mapper for Go
goql 17 0 Generate Golang database query code, spirit from mybatis/ibatis.
light 16 2 Generate Golang database query code, spirit from mybatis/ibatis.
osm 15 9 go object sql mapping and template,A simple ORM.simplified mybaits.
sqlt 7 10 Sqlt is a wrapper package for jmoiron/sqlx.This wrapper build based on tsenart/nap master-slave and its load-balancing configuration with some modification
orm 4 1 Simple and compact Golang VERSION of ORM
huge 3 1 Go huge CRUD package and SQL builder
gobatis 2 3 an orm like ibatis (java) for golang
db 2 0 The upper.io/db.v3 package for Go is a productive data access layer for Go that provides a common interface to work with different data sources such as PostgreSQL, MySQL, SQLite, MSSQL, QL and MongoDB.
go-bed 1 1 A high performance and lack use of reflection and Assertion Golang Framework.

Above database framework, a lot of libraries also use SQL Builder as a database framework auxiliary library, the following also introduces some OF my KNOWN SQL Builder development library.

Project Name Stars Forks Description
squirrel 1199 97 Fluent SQL generation for golang
goqu 336 32 SQL builder and query library for golang
sqrl 79 97 Fluent SQL generation for golang
sqlm 66 2 A minimalist sql builder for Golang
go-xorm/builder 25 6 Lightweight and fast SQL builder for Go and XORM
sqlabble 2 2 SQL query builder with type support.

Golang SQL Builder Benchmark compares the performance of some SQL Build libraries

Benchmarks

Go test bench =. – benchmem | t on the column – 2.6 GHz i5 Macbook Pro:

BenchmarkDbrSelectSimple 500000 2610 ns/op 864 B/op 14 allocs/op BenchmarkDbrSelectConditional 500000 3808 ns/op 1031 B/op 19 allocs/op BenchmarkDbrSelectComplex 200000 11585 ns/op 3323 B/op 53 allocs/op BenchmarkDbrSelectSubquery 200000 10025 ns/op 2851 B/op 40 allocs/op BenchmarkDbrInsert 500000 3717 ns/op 1136 B/op 19 allocs/op BenchmarkDbrUpdateSetColumns 300000 4106 ns/op 1038 B/op 24 allocs/op BenchmarkDbrUpdateSetMap 300000 5396 ns/op 1388 B/op 26 allocs/op BenchmarkDbrDelete 1000000 2150 ns/op 482 B/op 13 allocs/op BenchmarkGoquSelectSimple 100000 15180 ns/op 3282 B/op 46 allocs/op BenchmarkGoquSelectConditional 100000 19655 ns/op 4258 B/op 61 allocs/op BenchmarkGoquSelectComplex 30000 50628 ns/op 11414 B/op 215 allocs/op BenchmarkSqrlSelectSimple 500000 3555 ns/op 952 B/op 15 allocs/op BenchmarkSqrlSelectConditional 300000 4377 ns/op 1112 B/op 20 allocs/op BenchmarkSqrlSelectComplex 100000 24040 ns/op 4751 B/op 100 allocs/op BenchmarkSqrlSelectSubquery 100000 26203 ns/op 3560 B/op 67 allocs/op BenchmarkSqrlSelectMoreComplex 30000 47018 ns/op 7256 B/op 150 allocs/op BenchmarkSqrlInsert 200000 7773 ns/op 1304 B/op  25 allocs/op BenchmarkSqrlUpdateSetColumns 200000 8633 ns/op 1369 B/op 32 allocs/op BenchmarkSqrlUpdateSetMap 200000 15786 ns/op 1788 B/op 36 allocs/op BenchmarkSqrlDelete 500000 3669 ns/op 496 B/op 12 allocs/op BenchmarkSquirrelSelectSimple 100000 14934 ns/op 2737 B/op 52 allocs/op BenchmarkSquirrelSelectConditional 100000 18034 ns/op 4023 B/op 84 allocs/op BenchmarkSquirrelSelectComplex 20000 63096 ns/op 12742 B/op 283 allocs/op BenchmarkSquirrelSelectSubquery 30000 48956 ns/op 9954 B/op 206 allocs/op BenchmarkSquirrelSelectMoreComplex 20000 83842  ns/op 17153 B/op 386 allocs/op BenchmarkSquirrelInsert 100000 14517 ns/op 3356 B/op 75 allocs/op BenchmarkSquirrelUpdateSetColumns 100000 23995 ns/op 4787 B/op 108 allocs/op BenchmarkSquirrelUpdateSetMap 50000 27141 ns/op 5203 B/op 112 allocs/op BenchmarkSquirrelDelete 100000 16728 ns/op 2815 B/op 67 allocs/opCopy the code