dbeval

package module
v0.0.0-...-1118fef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 32 Imported by: 0

README

dbeval

Comparison of Go libraries for working with PostgreSQL

Runs benchmarks on the same "typical" database workflow implemented in various ways.

Latest Results

results.md and its chart are regenerated by the Benchmarks workflow whenever the code or its dependencies change on main. It runs on a shared GitHub-hosted runner, so compare implementations within one run rather than absolute numbers across runs.

Each implementation aims to be idiomatic for its library and to use the features that make it fastest for the workload: single-statement (or COPY) bulk inserts, the library's statement caching, and the fastest driver it supports.

⚠️ Warning: calls DROP DATABASE on local postgres instance! ⚠️

# Run tests
go test ./...

# Run benchmarks and write the report
go test -run '^$' -bench . -benchmem -count 6 . | tee bench.txt
go run ./internal/benchreport -svg results.svg bench.txt > results.md

# Reset if cleanup was not performed by previous run
psql postgres -c 'DROP DATABASE dbeval_db'
Style Note

Don't copy the check function to your own code! More often than not you want to return errors to your caller, with optional context from your error site. When you get ready to show the error to your user, either print it out or display it, optionally translating into an understandable error message. I'm using panics here to simplify the test harness. The DB manipulation implementations then conform to that. This is not a typical use-case so it's not likely to be the best approach for your problem.

Implementated
PRs Welcome

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	bun.BaseModel `bun:"table:articles,alias:ar" xorm:"-"`

	ID          int64     `db:"id" gorm:"primaryKey" xorm:"pk 'id'" bun:"id,pk,autoincrement"`
	Title       string    `db:"title"`
	Body        string    `db:"body"`
	PublishedAt time.Time `db:"published_at" xorm:"TIMESTAMPZ"`
}

func (Article) TableName

func (Article) TableName() string

type Author

type Author struct {
	bun.BaseModel `bun:"table:authors,alias:au" xorm:"-"`

	ID   int64  `db:"id" gorm:"primaryKey" xorm:"pk 'id'" bun:"id,pk,autoincrement"`
	Name string `db:"name"`
}

func (Author) TableName

func (Author) TableName() string

type Bun

type Bun struct {
	// contains filtered or unexported fields
}

func (*Bun) Connect

func (b *Bun) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Bun) CreateDatabase

func (b *Bun) CreateDatabase()

func (*Bun) CreateSchema

func (b *Bun) CreateSchema()

func (*Bun) DropDatabase

func (b *Bun) DropDatabase()

func (*Bun) FindAuthorByID

func (b *Bun) FindAuthorByID(id int64) *Author

func (*Bun) FindAuthorsByName

func (b *Bun) FindAuthorsByName(name string) []*Author

func (*Bun) InsertArticles

func (b *Bun) InsertArticles(as []*Article)

func (*Bun) InsertAuthors

func (b *Bun) InsertAuthors(as []*Author)

func (*Bun) RecentArticles

func (b *Bun) RecentArticles(n int) []*Article

type BunPGX

type BunPGX struct {
	Bun
}

func (*BunPGX) Connect

func (b *BunPGX) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

type DBR

type DBR struct {
	// contains filtered or unexported fields
}

func (*DBR) Connect

func (p *DBR) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*DBR) CreateDatabase

func (p *DBR) CreateDatabase()

func (*DBR) CreateSchema

func (p *DBR) CreateSchema()

func (*DBR) DropDatabase

func (p *DBR) DropDatabase()

func (*DBR) FindAuthorByID

func (p *DBR) FindAuthorByID(id int64) *Author

func (*DBR) FindAuthorsByName

func (p *DBR) FindAuthorsByName(name string) []*Author

func (*DBR) InsertArticles

func (p *DBR) InsertArticles(as []*Article)

func (*DBR) InsertAuthors

func (p *DBR) InsertAuthors(as []*Author)

func (*DBR) RecentArticles

func (p *DBR) RecentArticles(n int) []*Article

type Ent

type Ent struct {
	// contains filtered or unexported fields
}

func (*Ent) Connect

func (e *Ent) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Ent) CreateDatabase

func (e *Ent) CreateDatabase()

func (*Ent) CreateSchema

func (e *Ent) CreateSchema()

CreateSchema uses the shared schema.sql rather than e.client.Schema.Create so that ent runs against the same UNLOGGED tables as every other implementation; ent's migrations would create logged tables, which are slower to write to.

func (*Ent) DropDatabase

func (e *Ent) DropDatabase()

func (*Ent) FindAuthorByID

func (e *Ent) FindAuthorByID(id int64) *Author

func (*Ent) FindAuthorsByName

func (e *Ent) FindAuthorsByName(name string) []*Author

func (*Ent) InsertArticles

func (e *Ent) InsertArticles(as []*Article)

func (*Ent) InsertAuthors

func (e *Ent) InsertAuthors(as []*Author)

func (*Ent) RecentArticles

func (e *Ent) RecentArticles(n int) []*Article

type GoPG

type GoPG struct {
	// contains filtered or unexported fields
}

func (*GoPG) Connect

func (g *GoPG) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*GoPG) CreateDatabase

func (g *GoPG) CreateDatabase()

func (*GoPG) CreateSchema

func (g *GoPG) CreateSchema()

func (*GoPG) DropDatabase

func (g *GoPG) DropDatabase()

func (*GoPG) FindAuthorByID

func (g *GoPG) FindAuthorByID(id int64) *Author

func (*GoPG) FindAuthorsByName

func (g *GoPG) FindAuthorsByName(name string) []*Author

func (*GoPG) InsertArticles

func (g *GoPG) InsertArticles(as []*Article)

func (*GoPG) InsertAuthors

func (g *GoPG) InsertAuthors(as []*Author)

func (*GoPG) RecentArticles

func (g *GoPG) RecentArticles(n int) []*Article

type Gorm

type Gorm struct {
	// contains filtered or unexported fields
}

func (*Gorm) Connect

func (g *Gorm) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Gorm) CreateDatabase

func (g *Gorm) CreateDatabase()

func (*Gorm) CreateSchema

func (g *Gorm) CreateSchema()

func (*Gorm) DropDatabase

func (g *Gorm) DropDatabase()

func (*Gorm) FindAuthorByID

func (g *Gorm) FindAuthorByID(id int64) *Author

func (*Gorm) FindAuthorsByName

func (g *Gorm) FindAuthorsByName(name string) []*Author

func (*Gorm) InsertArticles

func (g *Gorm) InsertArticles(as []*Article)

func (*Gorm) InsertAuthors

func (g *Gorm) InsertAuthors(as []*Author)

func (*Gorm) RecentArticles

func (g *Gorm) RecentArticles(n int) []*Article

type Implementation

type Implementation interface {
	Connect(string, time.Duration, int, int)
	CreateDatabase()
	DropDatabase()
	CreateSchema()
	InsertAuthors([]*Author)
	InsertArticles([]*Article)
	FindAuthorByID(int64) *Author
	FindAuthorsByName(string) []*Author
	RecentArticles(int) []*Article
}

type Memory

type Memory struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Memory) Connect

func (m *Memory) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Memory) CreateDatabase

func (m *Memory) CreateDatabase()

func (*Memory) CreateSchema

func (m *Memory) CreateSchema()

func (*Memory) DropDatabase

func (m *Memory) DropDatabase()

func (*Memory) FindAuthorByID

func (m *Memory) FindAuthorByID(id int64) *Author

func (*Memory) FindAuthorsByName

func (m *Memory) FindAuthorsByName(name string) []*Author

func (*Memory) InsertArticles

func (m *Memory) InsertArticles(as []*Article)

func (*Memory) InsertAuthors

func (m *Memory) InsertAuthors(as []*Author)

func (*Memory) RecentArticles

func (m *Memory) RecentArticles(n int) []*Article

type Ozzo

type Ozzo struct {
	// contains filtered or unexported fields
}

func (*Ozzo) Connect

func (p *Ozzo) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Ozzo) CreateDatabase

func (p *Ozzo) CreateDatabase()

func (*Ozzo) CreateSchema

func (p *Ozzo) CreateSchema()

func (*Ozzo) DropDatabase

func (p *Ozzo) DropDatabase()

func (*Ozzo) FindAuthorByID

func (p *Ozzo) FindAuthorByID(id int64) *Author

func (*Ozzo) FindAuthorsByName

func (p *Ozzo) FindAuthorsByName(name string) []*Author

func (*Ozzo) InsertArticles

func (p *Ozzo) InsertArticles(as []*Article)

func (*Ozzo) InsertAuthors

func (p *Ozzo) InsertAuthors(as []*Author)

func (*Ozzo) RecentArticles

func (p *Ozzo) RecentArticles(n int) []*Article

type PGX

type PGX struct {
	// contains filtered or unexported fields
}

func (*PGX) Connect

func (p *PGX) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*PGX) CreateDatabase

func (p *PGX) CreateDatabase()

func (*PGX) CreateSchema

func (p *PGX) CreateSchema()

func (*PGX) DropDatabase

func (p *PGX) DropDatabase()

func (*PGX) FindAuthorByID

func (p *PGX) FindAuthorByID(id int64) *Author

func (*PGX) FindAuthorsByName

func (p *PGX) FindAuthorsByName(name string) []*Author

func (*PGX) InsertArticles

func (p *PGX) InsertArticles(as []*Article)

func (*PGX) InsertAuthors

func (p *PGX) InsertAuthors(as []*Author)

func (*PGX) RecentArticles

func (p *PGX) RecentArticles(n int) []*Article

type PGXStdlib

type PGXStdlib struct {
	// contains filtered or unexported fields
}

func (*PGXStdlib) Connect

func (p *PGXStdlib) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*PGXStdlib) CreateDatabase

func (p *PGXStdlib) CreateDatabase()

func (*PGXStdlib) CreateSchema

func (p *PGXStdlib) CreateSchema()

func (*PGXStdlib) DropDatabase

func (p *PGXStdlib) DropDatabase()

func (*PGXStdlib) FindAuthorByID

func (p *PGXStdlib) FindAuthorByID(id int64) *Author

func (*PGXStdlib) FindAuthorsByName

func (p *PGXStdlib) FindAuthorsByName(name string) []*Author

func (*PGXStdlib) InsertArticles

func (p *PGXStdlib) InsertArticles(as []*Article)

func (*PGXStdlib) InsertAuthors

func (p *PGXStdlib) InsertAuthors(as []*Author)

func (*PGXStdlib) RecentArticles

func (p *PGXStdlib) RecentArticles(n int) []*Article

type PQ

type PQ struct {
	// contains filtered or unexported fields
}

func (*PQ) Connect

func (p *PQ) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*PQ) CreateDatabase

func (p *PQ) CreateDatabase()

func (*PQ) CreateSchema

func (p *PQ) CreateSchema()

func (*PQ) DropDatabase

func (p *PQ) DropDatabase()

func (*PQ) FindAuthorByID

func (p *PQ) FindAuthorByID(id int64) *Author

func (*PQ) FindAuthorsByName

func (p *PQ) FindAuthorsByName(name string) []*Author

func (*PQ) InsertArticles

func (p *PQ) InsertArticles(as []*Article)

func (*PQ) InsertAuthors

func (p *PQ) InsertAuthors(as []*Author)

func (*PQ) RecentArticles

func (p *PQ) RecentArticles(n int) []*Article

type SQLC

type SQLC struct {
	// contains filtered or unexported fields
}

func (*SQLC) Connect

func (p *SQLC) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*SQLC) CreateDatabase

func (p *SQLC) CreateDatabase()

func (*SQLC) CreateSchema

func (p *SQLC) CreateSchema()

func (*SQLC) DropDatabase

func (p *SQLC) DropDatabase()

func (*SQLC) FindAuthorByID

func (p *SQLC) FindAuthorByID(id int64) *Author

func (*SQLC) FindAuthorsByName

func (p *SQLC) FindAuthorsByName(name string) []*Author

func (*SQLC) InsertArticles

func (p *SQLC) InsertArticles(as []*Article)

func (*SQLC) InsertAuthors

func (p *SQLC) InsertAuthors(as []*Author)

func (*SQLC) RecentArticles

func (p *SQLC) RecentArticles(n int) []*Article

type SQLX

type SQLX struct {
	// contains filtered or unexported fields
}

func (*SQLX) Connect

func (p *SQLX) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*SQLX) CreateDatabase

func (p *SQLX) CreateDatabase()

func (*SQLX) CreateSchema

func (p *SQLX) CreateSchema()

func (*SQLX) DropDatabase

func (p *SQLX) DropDatabase()

func (*SQLX) FindAuthorByID

func (p *SQLX) FindAuthorByID(id int64) *Author

func (*SQLX) FindAuthorsByName

func (p *SQLX) FindAuthorsByName(name string) []*Author

func (*SQLX) InsertArticles

func (p *SQLX) InsertArticles(as []*Article)

func (*SQLX) InsertAuthors

func (p *SQLX) InsertAuthors(as []*Author)

func (*SQLX) RecentArticles

func (p *SQLX) RecentArticles(n int) []*Article

type UpperDB

type UpperDB struct {
	// contains filtered or unexported fields
}

func (*UpperDB) Connect

func (p *UpperDB) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*UpperDB) CreateDatabase

func (p *UpperDB) CreateDatabase()

func (*UpperDB) CreateSchema

func (p *UpperDB) CreateSchema()

func (*UpperDB) DropDatabase

func (p *UpperDB) DropDatabase()

func (*UpperDB) FindAuthorByID

func (p *UpperDB) FindAuthorByID(id int64) *Author

func (*UpperDB) FindAuthorsByName

func (p *UpperDB) FindAuthorsByName(name string) []*Author

func (*UpperDB) InsertArticles

func (p *UpperDB) InsertArticles(as []*Article)

func (*UpperDB) InsertAuthors

func (p *UpperDB) InsertAuthors(as []*Author)

func (*UpperDB) RecentArticles

func (p *UpperDB) RecentArticles(n int) []*Article

type Xorm

type Xorm struct {
	// contains filtered or unexported fields
}

func (*Xorm) Connect

func (x *Xorm) Connect(ds string, connLifetime time.Duration, idleConns, openConns int)

func (*Xorm) CreateDatabase

func (x *Xorm) CreateDatabase()

func (*Xorm) CreateSchema

func (x *Xorm) CreateSchema()

func (*Xorm) DropDatabase

func (x *Xorm) DropDatabase()

func (*Xorm) FindAuthorByID

func (x *Xorm) FindAuthorByID(id int64) *Author

func (*Xorm) FindAuthorsByName

func (x *Xorm) FindAuthorsByName(name string) []*Author

func (*Xorm) InsertArticles

func (x *Xorm) InsertArticles(as []*Article)

func (*Xorm) InsertAuthors

func (x *Xorm) InsertAuthors(as []*Author)

func (*Xorm) RecentArticles

func (x *Xorm) RecentArticles(n int) []*Article

Directories

Path Synopsis
ent
internal
benchreport command
Command benchreport turns this repository's `go test -bench` output into a Markdown report: a summary ranking each implementation by its time relative to the fastest implementation, averaged across all benchmarks, followed by a table per benchmark sorted fastest first.
Command benchreport turns this repository's `go test -bench` output into a Markdown report: a summary ranking each implementation by its time relative to the fastest implementation, averaged across all benchmarks, followed by a table per benchmark sorted fastest first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址