Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 516 Bytes

README.md

File metadata and controls

32 lines (23 loc) · 516 Bytes

Rowmap

A Go library to map SQL query results to Go structs.

Basic usage

Install

go get github.com/spearson78/rowmap

Define a struct and a mapper from an sql.Rows to your struct

type TestStruct struct {
	Id  int64
	Col string
}

func testStructMapper(row *sql.Rows) (TestStruct, error) {
	var e TestStruct
	err := row.Scan(&e.Id, &e.Col)
	return e, err
}

Execute queries

entities, err := Query(db,testStructMapper, "SELECT ID,COL FROM TEST WHERE ID IN(?,?) ORDER BY ID DESC", 1, 2)