Skip to content

Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.

License

Notifications You must be signed in to change notification settings

AlexanderMatveev/dbmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DbMap

Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.

Go Report Card

Usage

import (
    "github.com/AlexanderMatveev/dbmap"
    "github.com/Masterminds/squirrel"
)

type Entity struct {
    Id            int       `db:"id"`
    Name          string    `db:"name"`
    DateTimeField time.Time `db:"created_at"`
    FieldNotIdDb  int
    NullableField *int
}

var structColumns = dbmap.Columns(reflect.TypeOf(Entity{}))

func main(){
    var e Entity
    // ...
    squirrel.Select(structColumns...)
    // ...
    rows.Scan(dbmap.Scan(&e)...)
    // ...
    squirrel.Insert("table").Columns(structColumns...).Values(dbmap.Values(e)...)
    // ...
}

About

Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages