pg
Golang ORM with focus on PostgreSQL features and performance
What is pg?
Golang ORM with focus on PostgreSQL features and performance
Overview of pg
What it is
pg is a Golang ORM (Object-Relational Mapping) library focused on PostgreSQL features and performance. It provides a high-level interface for interacting with PostgreSQL databases, supporting both ORM-style model operations and raw SQL queries. The project is currently in maintenance mode, with new development happening in the Bun repository which supports PostgreSQL, MySQL, MariaDB, and SQLite.
Key features
- Supports basic types: integers, floats, string, bool, time.Time, net.IP, net.IPNet, and sql.Null* types.
- Structs, maps, and arrays are marshalled as JSON by default; supports PostgreSQL multidimensional arrays and Hstore.
- All struct fields are nullable by default; zero values are marshalled as SQL NULL unless marked with
pg:,notnullor `pg:`,use_zero. - Supports transactions, prepared statements, notifications via LISTEN/NOTIFY, COPY FROM/TO, and context-based timeouts and cancellation.
- Automatic connection pooling with circuit breaker support and query retry on network errors.
- ORM supports has one, belongs to, has many, and many to many relationships with composite/multi-column primary keys, soft deletes, and table creation from structs.
- Bulk/batch inserts, updates, and deletes; common table expressions (WITH); CountEstimate using EXPLAIN; ForEach for row-by-row processing.
Use cases
pg is suitable for building Go applications that require a PostgreSQL database with ORM capabilities, such as web services, APIs, and data processing pipelines. It can be used in projects that need efficient batch operations, complex relationships, or direct SQL access alongside ORM convenience.
Getting started
shellgo mod init github.com/my/repogo get github.com/go-pg/pg/v10
License and pricing
pg is open source under the BSD-2-Clause license. No pricing information is provided.
Based on the project's public README and repository metadata.