Skip to content
/ mapper Public

Mapping a sql/database Scan-like output to a struct with ease, and some helper functions to write them.

License

Notifications You must be signed in to change notification settings

dav-m85/mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mapper

mapper provides a way of mapping a sql/database Scan-like output to a struct, and some helper functions to write them.

When manipulating raw queries, it's easy to introduce bug by misordering fields, forgetting about names.

var ma = Mapper(Record{}, "*")

db := sql.DB{}

rows, _ := db.Query(`SELECT ` + ma.ColumnsString() + ` FROM Records`)
for rows.Next() {
    var r Record
    rows.Scan(ma.Addrs(&r)...)
}

Installation

go get github.com/dav-m85/mapper

Or you can just copypaste mapper.go in your project directly. Less deps is good.

About

Mapping a sql/database Scan-like output to a struct with ease, and some helper functions to write them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages