# sqlk
the simplest sql library for Golang
#### installation
```
go get github.com/saxoned/sqlk
```
#### quick start
+ create engine
```
engine, err := sqlk.NewEngine("postgres", "postgres://postgres:123456@localhost:5432/postgres?sslmode=disable")
```
+ add global sqlk err handler (optional)
```
func failOnError(err error) {
log.Printf("sqlk error:%s", err.Error())
}
engine.errHandler = failOnError
```
+ query 1 to map
```
r := engine.Query(`select * from "user"`).GetMap()
```
+ query 1 to struct
```
user := new(struct {
Id string `sql:"id"`
Age int64 `sql:"age"`
Sex bool `sql:"sex"`
Name string `sql:"name"`
})
engine.Query(`select * from "user" where name = $1 `, "cc").Get(user)
```
+ query all to map
```
r := engine.Query(`select * from "user"`).FindMap()
```
+ query all to struct slice
```
defer engine.Close()
var users []struct {
Id string `sql:"id"`
Age int64 `sql:"age"`
Sex bool `sql:"sex"`
Name string `sql:"name"`
}
engine.Query(`select * from "user"`).Find(&users)
```
有疑问加站长微信联系(非本文作者)