NLG PostgreSQL Driver
PostgreSQL driver for the NetLife Guru Go database layer.
Use postgres to connect PostgreSQL databases to the shared github.com/netlifeguru/db repository API with mapper-backed result scanning.

About
postgres is the PostgreSQL driver package for the NetLife Guru Go database stack.
It provides real PostgreSQL database connections that implement the shared db.Conn interface from github.com/netlifeguru/db.
Application code normally imports this package to open PostgreSQL connections, while repository code can depend on the shared db package.
How It Fits Together
| Layer |
Package |
Purpose |
| Mapper |
github.com/netlifeguru/mapper |
Row-to-struct and map scanning |
| DB |
github.com/netlifeguru/db |
Shared query and repository API |
| Driver |
github.com/netlifeguru/db-postgres |
Real PostgreSQL database connections |
Features
- PostgreSQL Driver: Connects the shared NetLife Guru database layer to PostgreSQL
- Shared DB Interface: Provides connections compatible with
db.Conn
- Repository Friendly: Lets repository code use common
db helpers such as List, Get, Value, and Maps
- Mapper Integration: Uses
github.com/netlifeguru/mapper for struct, map, and scalar result scanning
- SQL Model Support: Works with PostgreSQL
model.psql files through the shared db package
- Dialect SQL Support: Supports PostgreSQL-specific SQL through
db.DialectSQL
- Transaction Support: Supports transaction workflows through the shared database layer
- Explicit SQL: Designed for applications that prefer direct SQL and typed repository helpers
- Standard Go Friendly: Built around context-aware operations, interfaces, structs, and explicit error handling
Requirements
This package requires Go 1.25 or newer.
- Go:
1.25 or newer
- Shared dependencies:
github.com/netlifeguru/db, github.com/netlifeguru/mapper
- Database: PostgreSQL-compatible server
Installation
Add the PostgreSQL driver to your project using go get:
go get github.com/netlifeguru/db-postgres
This also installs the shared db and mapper packages required by the driver.
Basic Usage
import (
"context"
"github.com/netlifeguru/db"
"github.com/netlifeguru/db-postgres"
)
Once a PostgreSQL connection is created, repository code can work with the shared db.Conn interface:
func ListUsers(ctx context.Context, conn db.Conn) ([]User, error) {
return db.List[User](ctx, conn, db.Raw(`
SELECT *
FROM users
ORDER BY created_at DESC
`))
}
Dialect SQL
PostgreSQL queries can be used directly or selected from db.DialectSQL in multi-driver applications.
queries := struct {
GetUser db.DialectSQL `json:"GetUser"`
}{
GetUser: db.DialectSQL{
Postgres: `SELECT * FROM users WHERE id = $1`,
Mysql: `SELECT * FROM users WHERE id = ?`,
Scylla: `SELECT * FROM users WHERE id = ?`,
},
}
The active PostgreSQL connection uses the PostgreSQL query variant.
Documentation
Full package documentation, guides, and examples are available at:
https://netlife.guru/docs/go/db/getting-started/installation#postgresql
Shared database layer documentation:
https://netlife.guru/docs/go/db
API reference is also available on pkg.go.dev:
https://pkg.go.dev/github.com/netlifeguru/db-postgres
Notes
- This package is the PostgreSQL driver for the shared NetLife Guru database layer.
- Repository code can depend on
github.com/netlifeguru/db while application setup imports this driver.
- Review package-specific concurrency behavior before using it in highly parallel workloads.
- Check performance characteristics when using this package in latency-sensitive paths.
- See the package documentation and examples for limitations and recommended usage patterns.
Versioning
This project follows Semantic Versioning.
See CHANGELOG.md for release history and breaking changes.
Contributing
Community contributions, feedback, and improvements are welcome.
Please read CONTRIBUTING.md before submitting pull requests or opening issues.
Code of Conduct
This project follows a Code of Conduct.
Please read CODE_OF_CONDUCT.md before contributing or participating in discussions.
Author
Created and maintained by NetLife Guru s.r.o.
License
MIT License. See LICENSE.