在Github中stars數最多的Go數據庫框架庫集合

在Go語言世界中,beego ormgormsqlxgorpxorm是我已知在Github中stars數最多Go數據庫框架,這幾個都是Go語言世界中老牌數據庫框架庫。java

其中beego ormbeego自帶的orm框架庫,統計star數的時候是按beego的star數統計的(beego以前還有一個數據庫框架beedb,因爲謝大在2014年就未在維護此庫,因此沒有出如今個人統計列表中)。mysql

sqlxxorm則是筆者最喜歡和實際開發中最多使用的Go數據庫框架庫。值的一提的是sqlx還有3個擴展庫,一個是sqalx,它使sqlx提供對嵌套事務的支持,另外兩個名字都叫sqlt,其中第一個sqlt庫,使sqlx支持sql模板和類mybatis的sql配置;第二個sqlt庫,則使sqlx支持數據庫主從數據源,讀寫分離;git

另一個值的一提的是xorm也有一個定製加強版xormplus/xorm,使得xorm支持sql模板和類mybatis的sql配置,支持動態sql,支持嵌套事務,支持相似Java中Spring的事務傳播機制,支持數據庫的讀寫分離(master/slave)。同時它和xorm同樣內置支持SQL Builder。github

最後還有一個比較有意思的Go數據庫框架庫是argen,它在具體實現中使用了annotation方式,這在Go語言開發庫中是比較少見的,對筆者而言是一個值得閱讀源碼和學習的庫,它使Go語言又多了一種思惟方式。golang

在實際開發中筆者常常是依據業務複雜度,數據庫sql複雜度,在sqlxxormxormplus/xorm中進行數據庫框架庫選型,筆者大多數時候更傾向xormplus/xorm。若是您也有好的Go語言數據庫框架推薦,不妨在留言區留言,你們一塊兒交流分享。web

下面是我整理的Go語言數據庫框架列表,其中有一些源代碼非常小巧精悍(雖然star數很少,但我仍是羅列出來了),很是適合學習閱讀,幫助本身提升對Go語言程序庫的設計實現的理解。redis

Project Name Stars Forks Description
beego orm 12216 2814 A powerful orm framework for go.(beego自帶的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 http://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(定製加強版)
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 簡單小巧的golang版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 reflect and assertion golang framework.(帶有一個orm框架)

以上數據庫框架中,不少庫還大量使用SQL Builder來做爲數據庫框架輔助庫使用,下面也介紹一些我已知的SQL Builder開發庫。sql

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中對部分SQL Build庫的性能測試對比數據chrome

Benchmarks

go test -bench=. -benchmem | column -t on 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/op
相關文章
相關標籤/搜索