Description
gocraft/dbr provides additions to Go's database/sql for super fast performance and convenience.
gocraft/dbr (database records) alternatives and similar packages
Based on the "Database" category.
Alternatively, view dbr alternatives based on common mentions on social networks and blogs.
-
prometheus
The Prometheus monitoring system and time series database. -
cockroach
CockroachDB - the open source, cloud-native distributed SQL database. -
influxdb
Scalable datastore for metrics, events, and real-time analytics -
Milvus
A cloud-native vector database, storage for next generation AI applications -
tidb
TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial -
vitess
Vitess is a database clustering system for horizontal scaling of MySQL. -
dgraph
The high-performance database for modern applications -
TinyGo
Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM. -
rqlite
The lightweight, distributed relational database built on SQLite -
migrate
Database migrations. CLI and Golang library. -
groupcache
groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases. -
VictoriaMetrics
VictoriaMetrics: fast, cost-effective monitoring solution and time series database -
pgweb
Cross-platform client for PostgreSQL databases -
immudb
immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history -
go-cache
An in-memory key:value store/cache (similar to Memcached) library for Go, suitable for single-machine applications. -
BigCache
Efficient cache for gigabytes of data written in Go. -
bytebase
Database DevOps and CI/CD for Developer, DBA and Platform Engineering team. -
dtm
此仓库应常青藤爸爸要求,已停止维护,请移步 https://github.com/dtm-labs/dtf -
go-mysql-elasticsearch
Sync MySQL data into elasticsearch -
ledisdb
A high performance NoSQL Database Server powered by Go -
rosedb
Lightweight, fast and reliable key/value storage engine based on Bitcask. -
pREST
PostgreSQL ➕ REST, low-code, simplify and accelerate development, ⚡ instant, realtime, high-performance on any Postgres application, existing or new -
buntdb
BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support -
dbmate
:rocket: A lightweight, framework-agnostic database migration tool. -
go-memdb
Golang in-memory database built on immutable radix trees -
xo
Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server -
LinDB
LinDB is a scalable, high performance, high availability distributed time series database. -
tiedot
A rudimentary implementation of a basic document (NoSQL) database in Go -
nutsdb
A simple, fast, embeddable, persistent key/value store written in pure Go. It supports fully serializable transactions and many data structures such as list, set, sorted set. -
cache2go
Concurrency-safe Go caching library with expiration capabilities and access counters -
GCache
An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC -
fastcache
Fast thread-safe inmemory cache for big number of entries in Go. Minimizes GC overhead -
CovenantSQL
A decentralized, trusted, high performance, SQL database with blockchain features -
lotusdb
Most advanced key-value store written in Go, extremely fast, compatible with LSM tree and B+ tree, optimization of badger and bbolt.
Tired of breaking your main and manually rebasing outdated pull requests?
Do you think we are missing an alternative of gocraft/dbr (database records) or a related project?
README
gocraft/dbr (database records)
gocraft/dbr provides additions to Go's database/sql for super fast performance and convenience.
$ go get -u github.com/gocraft/dbr/v2
import "github.com/gocraft/dbr/v2"
Driver support
- MySQL
- PostgreSQL
- SQLite3
- MsSQL
Examples
See godoc for more examples.
Open connections
// create a connection (e.g. "postgres", "mysql", or "sqlite3")
conn, _ := Open("postgres", "...", nil)
conn.SetMaxOpenConns(10)
// create a session for each business unit of execution (e.g. a web request or goworkers job)
sess := conn.NewSession(nil)
// create a tx from sessions
sess.Begin()
Create and use Tx
sess := mysqlSession
tx, err := sess.Begin()
if err != nil {
return
}
defer tx.RollbackUnlessCommitted()
// do stuff...
tx.Commit()
SelectStmt loads data into structs
// columns are mapped by tag then by field
type Suggestion struct {
ID int64 // id, will be autoloaded by last insert id
Title NullString `db:"subject"` // subjects are called titles now
Url string `db:"-"` // ignored
secret string // ignored
}
// By default gocraft/dbr converts CamelCase property names to snake_case column_names.
// You can override this with struct tags, just like with JSON tags.
// This is especially helpful while migrating from legacy systems.
var suggestions []Suggestion
sess := mysqlSession
sess.Select("*").From("suggestions").Load(&suggestions)
SelectStmt with where-value interpolation
// database/sql uses prepared statements, which means each argument
// in an IN clause needs its own question mark.
// gocraft/dbr, on the other hand, handles interpolation itself
// so that you can easily use a single question mark paired with a
// dynamically sized slice.
sess := mysqlSession
ids := []int64{1, 2, 3, 4, 5}
sess.Select("*").From("suggestions").Where("id IN ?", ids)
SelectStmt with joins
sess := mysqlSession
sess.Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id")
sess.Select("*").From("suggestions").
LeftJoin("subdomains", "suggestions.subdomain_id = subdomains.id")
// join multiple tables
sess.Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id").
Join("accounts", "subdomains.accounts_id = accounts.id")
SelectStmt with raw SQL
SelectBySql("SELECT `title`, `body` FROM `suggestions` ORDER BY `id` ASC LIMIT 10")
InsertStmt adds data from struct
type Suggestion struct {
ID int64
Title NullString
CreatedAt time.Time
}
sugg := &Suggestion{
Title: NewNullString("Gopher"),
CreatedAt: time.Now(),
}
sess := mysqlSession
sess.InsertInto("suggestions").
Columns("title").
Record(&sugg).
Exec()
// id is set automatically
fmt.Println(sugg.ID)
InsertStmt adds data from value
sess := mysqlSession
sess.InsertInto("suggestions").
Pair("title", "Gopher").
Pair("body", "I love go.")
Benchmark (2018-05-11)
BenchmarkLoadValues/sqlx_10-8 5000 407318 ns/op 3913 B/op 164 allocs/op
BenchmarkLoadValues/dbr_10-8 5000 372940 ns/op 3874 B/op 123 allocs/op
BenchmarkLoadValues/sqlx_100-8 2000 584197 ns/op 30195 B/op 1428 allocs/op
BenchmarkLoadValues/dbr_100-8 3000 558852 ns/op 22965 B/op 937 allocs/op
BenchmarkLoadValues/sqlx_1000-8 1000 2319101 ns/op 289339 B/op 14031 allocs/op
BenchmarkLoadValues/dbr_1000-8 1000 2310441 ns/op 210092 B/op 9040 allocs/op
BenchmarkLoadValues/sqlx_10000-8 100 17004716 ns/op 3193997 B/op 140043 allocs/op
BenchmarkLoadValues/dbr_10000-8 100 16150062 ns/op 2394698 B/op 90051 allocs/op
BenchmarkLoadValues/sqlx_100000-8 10 170068209 ns/op 31679944 B/op 1400053 allocs/op
BenchmarkLoadValues/dbr_100000-8 10 147202536 ns/op 23680625 B/op 900061 allocs/op
Thanks & Authors
Inspiration from these excellent libraries:
- sqlx - various useful tools and utils for interacting with database/sql.
- Squirrel - simple fluent query builder.
Authors:
- Jonathan Novak -- https://github.com/cypriss
- Tai-Lin Chu -- https://github.com/taylorchu
- Sponsored by UserVoice
Contributors:
- Paul Bergeron -- https://github.com/dinedal - SQLite dialect
License
*Note that all licence references and agreements mentioned in the gocraft/dbr (database records) README section above
are relevant to that project's source code only.