Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pg

> 数据库
Open source

Golang ORM with focus on PostgreSQL features and performance

5.8K stars0 likes2 views
WebsiteGitHub

About

Golang ORM with focus on PostgreSQL features and performance

PostgreSQL client and ORM for Golang

Maintenance mode

go-pg is in a maintenance mode and only critical issues are addressed. New development happens in Bun repo which offers similar functionality but works with PostgreSQL, MySQL, MariaDB, and SQLite.

Golang ORM


  • Documentation
  • Reference
  • Examples
  • Example projects:
    • monetr - budgeting application focused on planning for recurring expenses
    • bunrouter
    • gin
    • go-kit
    • aah framework

Tutorials

  • GraphQL Tutorial on YouTube.
  • Modern API design with Golang, PostgreSQL and Docker

Ecosystem

  • Migrations by vmihailenco and robinjoseph08.
  • Genna - cli tool for generating go-pg models.
  • bigint - big.Int type for go-pg.
  • urlstruct to decode url.Values into structs.
  • Sharding.
  • go-pg-monitor - Prometheus metrics based on go-pg client stats.

Features

  • Basic types: integers, floats, string, bool, time.Time, net.IP, net.IPNet.
  • sql.NullBool, sql.NullString, sql.NullInt64, sql.NullFloat64 and pg.NullTime.
  • sql.Scanner and sql/driver.Valuer interfaces.
  • Structs, maps and arrays are marshalled as JSON by default.
  • PostgreSQL multidimensional Arrays using array tag and Array wrapper.
  • Hstore using hstore tag and Hstore wrapper.
  • Composite types.
  • All struct fields are nullable by default and zero values (empty string, 0, zero time, empty map or slice, nil ptr) are marshalled as SQL NULL. pg:",notnull" is used to add SQL NOT NULL constraint and pg:",use_zero" to allow Go zero values.
  • Transactions.
  • Prepared statements.
  • Notifications using LISTEN and NOTIFY.
  • Copying data using COPY FROM and COPY TO.
  • Timeouts and canceling queries using context.Context.
  • Automatic connection pooling with circuit breaker support.
  • Queries retry on network errors.
  • Working with models using ORM and SQL.
  • Scanning variables using ORM and SQL.
  • SelectOrInsert using on-conflict.
  • INSERT ... ON CONFLICT DO UPDATE using ORM.
  • Bulk/batch inserts, updates, and deletes.
  • Common table expressions using WITH and WrapWith.
  • CountEstimate using EXPLAIN to get estimated number of matching rows.
  • ORM supports has one, belongs to, has many, and many to many with composite/multi-column primary keys.
  • Soft deletes.
  • Creating tables from structs.
  • ForEach that calls a function for each row returned by the query without loading all rows into the memory.

Installation

go-pg supports 2 last Go versions and requires a Go version with modules support. So make sure to initialize a Go module:

bash
go mod init github.com/my/repo

And then install go-pg (note v10 in the import; omitting it is a popular mistake):

bash
go get github.com/go-pg/pg/v10

Quickstart

…

See also

  • Golang PostgreSQL
  • Golang HTTP router
  • Golang ClickHouse ORM
  • Golang msgpack
  • Distributed tracing tools

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Godatabasegogolanghstore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库