Cookies management by TermsFeed Cookie Consent

🐘 Best PostgreSQL database drivers and ORMs in Go

list postgresql db sql

Please consider supporting us by disabling your ad blocker

When you start a new project in Go, you probably always ask yourself about the data access layer. Use the generic database/sql interface and write queries by hand or use an ORM package, or tools to help generate queries? Which database driver to use? What packages to use to make your workflow fast and smooth? In this post we will try to review the best available drivers and ORM packages for the PostgreSQL database. Unfortunately, there are a lot of them, and they are all good enough, so the choice will not be easy, and you have to decide what is the most important for you 😉.


1. pgx

Recommended driver for a new project, actively maintained and developed. Low-level, fast, and performant. It consists of two components: driver and toolkit. The driver is compatible with the database/sql interface, while the toolkit contains PostgreSQL-specific features and functionalities that make your work easier, such as mapping between PostgreSQL and Go.


Package documentation: pgx

2. pq

Historically the most popular PostgreSQL driver for Go. Well tested and used in many existing projects. Currently only in the maintenance mode. As the authors themselves say:

“For users that require new features or reliable resolution of reported bugs, we recommend using pgx which is under active development.” – pq maintainers

However, if you are looking for a battle-tested and stable driver for Go, the pq is a great choice.


Package documentation: pg



One of the most popular ORM packages in Go, whose the main goal is to be developer-friendly. Officially supports PostgreSQL, MySQL, SQLite, and MSSQL. It is actively developed, has great documentation, and many features, like:



Package documentation: GORM

2. Bun

Bun is a SQL-first ORM that provides an ORM-like experience using good old SQL. It supports PostgreSQL, MySQL, MariaDB, MSSQL, and SQLite. Great documentation and essential features, useful in everyday work are its strong points:



Package documentation: Bun

3. ent

An entity framework for Go. It is the ORM developed by Facebook focusing on graph-based data models. The schema is defined as a graph structure in Go code, from which the model and operations are generated using code generation. It supports PostgreSQL, MySQL, MariaDB, TiDB, SQLite, and Gremlin.



Package documentation: ent

4. upper/db

A data access layer made for productivity. API is compatible with SQL and NoSQL databases like PostgreSQL, MySQL, MSSQL, CockroachDB, MongoDB, QL, and SQLite. It provides an agnostic API focused on working with collections of items, a SQL builder for more direct access to the database, and an ORM-like layer for mapping between a struct and a database table and working with the database in a more ORM-like style. Some features:



Package documentation: upper/db


Simple and powerful GORM alternative supporting PostgreSQL, MySQL, SQLite, MSSQL, MariaDB, TiDB, CockroachDB, and Oracle. Some of the features:



Package documentation: XORM

6. POP

It is part of the Buffalo Go web framework, deeply integrated, and recommended when using Buffalo. But can also be used as a stand-alone data access layer. POP follows conventions influenced by the ActiveRecord Ruby gem making it easy to do CRUD operations with basic ORM functionality, run migrations, and build/execute queries. It supports PostgreSQL, CockroachDB, MySQL, and SQLite databases.



Package documentation: POP

7. REL

REL is a modern ORM-ish data access layer for layered architecture. It is built with testability in mind and comes with its custom test library. It supports PostgreSQL, MySQL, MSSQL, and SQLite. Features:



Package documentation: REL

8. Beego ORM

This ORM is part of the Beego web framework. Heavily influenced by Django ORM and SQLAlchemy. It works with PostgreSQL, MySQL, and SQLite databases. The main features are: easy to use CRUD operations, Struct - Table mapping, raw SQL support and query builder, auto joins, transactions support.



Package documentation: Beego ORM

Thank you for being on our site 😊. If you like our tutorials and examples, please consider supporting us with a cup of coffee and we'll turn it into more great Go examples.

Have a great day!

🗂️ Introductory tutorial to SQLite in Go

Learn how to create SQLite repository and make basic operations
db sql sqlite