Installation
Install the mapper package into your Go project.
The mapper package requires Go 1.22 or newer.
mapper is a lightweight standalone package for scanning database rows into Go structs, maps, or custom row handlers.
It helps you map database results by column name instead of scan position, while staying independent from any specific database driver.
It supports:
- struct mapping using
dbandjsontags - scanning rows into
[]T - scanning rows into
map[string]any - filling structs from maps
- nullable values and pointer fields
- custom row mapping through the
ScanMapperinterface - database-agnostic row scanning through the
mapper.Rowsinterface
Install
Install the package using go get:
go get github.com/netlifeguru/mapperAfter installation, import the package into your application:
import "github.com/netlifeguru/mapper"The package is standalone and does not require the NetLifeGuru database layer.
You can use it directly with rows from MySQL, PostgreSQL, ScyllaDB, CockroachDB, MariaDB, or any other database driver that can be adapted to the mapper.Rows interface.
For clarity and consistency, the examples in this documentation use MySQL, but the same mapping concepts apply to other supported database systems.
Once installed, continue with the Quick Start guide to scan your first database rows into Go structs.