Build a Go web app that reads and writes data to a PostgreSQL database without writing raw SQL.
Store and query structured JSON data in PostgreSQL using JSONB columns from Go code.
Model related records like users and orders in Go structs and let the library handle the database joins.
Get live database change notifications in a Go app using PostgreSQL LISTEN and NOTIFY.
Requires a recent Go version with module support. Import path must include the version suffix v10, omitting it is a common mistake. Active development has moved to Bun.
go-pg is a library for Go developers that connects their applications to PostgreSQL databases. An ORM, which stands for Object-Relational Mapper, means it lets you work with database records as regular Go data structures instead of writing raw SQL by hand. You define your data shapes as Go structs, and the library handles translating operations like inserting a record or finding rows that match a condition into the appropriate database queries. The project is now in maintenance mode. Only critical bugs are being fixed, and active development has moved to a newer library called Bun, which offers similar functionality but also supports MySQL, MariaDB, and SQLite in addition to PostgreSQL. go-pg was built specifically around PostgreSQL and exposes features particular to that database: PostgreSQL array columns, the hstore key-value column type, JSONB columns, bulk insert and update operations, and live notifications through the database's LISTEN and NOTIFY system. The library manages a pool of database connections automatically and retries queries if a network error interrupts them. Relationships between tables are handled through the ORM layer. You can express that one record belongs to another, that one record has many related records, or that two types of records relate to each other through a joining table. Soft deletes are also supported, where a record is flagged as deleted rather than physically removed from the database. Installation requires a recent version of Go with module support. The library is imported as version 10, and the README notes that leaving the version number out of the import path is a common mistake.
← go-pg on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.