在Github中stars数最多的Go数据库框架库集合

在Go语言世界中,beego ormgormsqlxgorpxorm是我已知在Github中stars数最多Go数据库框架,这几个都是Go语言世界中老牌数据库框架库。

其中beego ormbeego自带的orm框架库,统计star数的时候是按beego的star数统计的(beego之前还有一个数据库框架beedb,由于谢大在2014年就未在维护此库,所以没有出现在我的统计列表中)。

sqlxxorm则是笔者最喜欢和实际开发中最多使用的Go数据库框架库。值的一提的是sqlx还有3个扩展库,一个是sqalx,它使sqlx提供对嵌套事务的支持,另外两个名字都叫sqlt,其中第一个sqlt库,使sqlx支持sql模板和类mybatis的sql配置;第二个sqlt库,则使sqlx支持数据库主从数据源,读写分离;

另外一个值的一提的是xorm也有一个定制增强版xormplus/xorm,使得xorm支持sql模板和类mybatis的sql配置,支持动态sql,支持嵌套事务,支持类似Java中Spring的事务传播机制,支持数据库的读写分离(master/slave)。同时它和xorm一样内置支持SQL Builder。

最后还有一个比较有意思的Go数据库框架库是argen,它在具体实现中使用了annotation方式,这在Go语言开发库中是比较少见的,对笔者而言是一个值得阅读源码和学习的库,它使Go语言又多了一种思维方式。

在实际开发中笔者经常是依据业务复杂度,数据库sql复杂度,在sqlxxormxormplus/xorm中进行数据库框架库选型,笔者大多数时候更倾向xormplus/xorm。如果您也有好的Go语言数据库框架推荐,不妨在留言区留言,大家一起交流分享。

下面是我整理的Go语言数据库框架列表,其中有一些源代码很是小巧精悍(虽然star数不多,但我还是罗列出来了),非常适合学习阅读,帮助自己提高对Go语言程序库的设计实现的理解。

Project NameStarsForksDescription
beego orm122162814A powerful orm framework for go.(beego自带的orm)
gorm6548809The fantastic ORM library for Golang, aims to be developer friendly
sqlx3244276general purpose extensions to golang’s database/sql
gorp2555306Go Relational Persistence – an ORM-ish library for Go
xorm2273341Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle http://xorm.io
xo1255103Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server
pg110470PostgreSQL ORM for Golang with focus on PostgreSQL features and performance
db97573Productive data access layer for Go.
dbr81687Additions to Go’s database/sql for super fast performance and convenience.
sqlboiler75564Generate a Go ORM tailored to your database schema.
hood65951Database agnostic ORM for Go
reform54619A better ORM for Go, based on non-empty interfaces and code generation.
godb49815A Go query builder and struct mapper.
qb49221The database toolkit for go
qbs46088QBS stands for Query By Struct. A Go ORM.
dat45937Go Postgres Data Access Toolkit
go-kallax44326Kallax is a PostgreSQL typesafe ORM for the Go language.
dotsql30819A Golang library for using SQL.
xormplus/xorm27848Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle(定制增强版)
jet19921Jet is a super-flexible and lightweight SQL interface for Go
goyesql1799Parse a file and associate SQL queries to a map. Useful for separating SQL from code logic.
ozzo-dbx17524A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
genmai14417Simple, better and easy-to-use ORM library for Golang
sqlt14323like mybatis see README-zh.md
squalor13221Go SQL utility library
argen1228An ORM code-generation tool for Go, provides ActiveRecord-like functionality for your types.
sqalx764Nested transactions for sqlx
goSQL641a ORM like library in Go (golang) that makes SQL easier to use.
gomodel557A lightweight, fast, orm-like library helps interactive with database
vivom531a powerful Go ORM library
orm4511golang ORM , mysql , sqllite3 , hash redis
ngorm292Neo GORM: The modern fork of gorm The fantastic ORM( Object Relational Mapper ) for Go
gatsby221Gatsby Database Toolkit For Go (ORM, SQL Builder and SQLUtils)
go-ormtools201A package with helper functions
orange194A lightweight Object Relational Mapper for Go
goql170Generate Golang database query code, spirit from mybatis/ibatis.
light162Generate Golang database query code, spirit from mybatis/ibatis.
osm159go object sql mapping and template,A simple ORM.simplified mybaits.
sqlt710Sqlt is a wrapper package for jmoiron/sqlx.This wrapper build based on tsenart/nap master-slave and its load-balancing configuration with some modification
orm41简单小巧的golang版orm
huge31Go huge CRUD package and SQL builder
gobatis23an orm like ibatis (java) for golang
db20The 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-bed11a high performance and lack use reflect and assertion golang framework.(带有一个orm框架)

以上数据库框架中,很多库还大量使用SQL Builder来作为数据库框架辅助库使用,下面也介绍一些我已知的SQL Builder开发库。

Project NameStarsForksDescription
squirrel119997Fluent SQL generation for golang
goqu33632SQL builder and query library for golang
sqrl7997Fluent SQL generation for golang
sqlm662A minimalist sql builder for Golang
go-xorm/builder256Lightweight and fast SQL builder for Go and XORM
sqlabble22SQL query builder with type support.

下面是Golang sql builder benchmark中对部分SQL Build库的性能测试对比数据

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
    原文作者:数据库基础
    原文地址: https://my.oschina.net/u/168737/blog/1531834
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞