PostgreSQL driver for the NetLife Guru Go database layer.
Use postgres to connect PostgreSQL databases to the shared
github.com/netlifeguru/dbrepository API with mapper-backed result scanning.
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.
| 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 |
- 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
dbhelpers such asList,Get,Value, andMaps - Mapper Integration: Uses
github.com/netlifeguru/mapperfor struct, map, and scalar result scanning - SQL Model Support: Works with PostgreSQL
model.psqlfiles through the shareddbpackage - 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
This package requires Go 1.25 or newer.
- Go:
1.25or newer - Shared dependencies:
github.com/netlifeguru/db,github.com/netlifeguru/mapper - Database: PostgreSQL-compatible server
Add the PostgreSQL driver to your project using go get:
go get github.com/netlifeguru/db-postgresThis also installs the shared db and mapper packages required by the driver.
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
`))
}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.
- github.com/netlifeguru/db — shared database layer
- github.com/netlifeguru/mapper — row-to-struct mapper
- github.com/netlifeguru/db-mysql — MySQL driver
- github.com/netlifeguru/db-scylla — ScyllaDB driver
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
- This package is the PostgreSQL driver for the shared NetLife Guru database layer.
- Repository code can depend on
github.com/netlifeguru/dbwhile 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.
This project follows Semantic Versioning.
See CHANGELOG.md for release history and breaking changes.
Community contributions, feedback, and improvements are welcome.
Please read CONTRIBUTING.md before submitting pull requests or opening issues.
This project follows a Code of Conduct.
Please read CODE_OF_CONDUCT.md before contributing or participating in discussions.
Created and maintained by NetLife Guru s.r.o.
- Documentation: https://netlife.guru/docs/go/postgres
- GitHub: https://github.com/netlifeguru
- Contact: info@netlife.guru
MIT License. See LICENSE.