https://github.com/alexandermatveev/dbmap
Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.
https://github.com/alexandermatveev/dbmap
Last synced: 11 months ago
JSON representation
Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.
- Host: GitHub
- URL: https://github.com/alexandermatveev/dbmap
- Owner: AlexanderMatveev
- License: mit
- Created: 2023-09-26T19:50:03.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-28T10:24:05.000Z (almost 3 years ago)
- Last Synced: 2025-02-28T11:58:53.547Z (over 1 year ago)
- Language: Go
- Homepage: https://pkg.go.dev/github.com/AlexanderMatveev/dbmap
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DbMap
Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.
[](https://goreportcard.com/report/github.com/AlexanderMatveev/dbmap)
## Usage
```go
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)...)
// ...
}
```