# 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)
```
#### 我不想用太臃肿的orm,标准库的sql查询又不是很方便,就写了sqlk,昨天才开始写,我也是初学者,有兴趣的大家一起学习~https://github.com/saxoned/sqlk
#1