Skip to main content

Create Client

db.NewClient with automatically read config by REX_ENV, set to "development" if missing.

c, err := db.NewClient()
c, err := db.NewClientWithEnv("development")

Query

The query methods support mapping columns into struct fileds via the db struct tag.

var res struct {
Count int `db:"count"`
}
err := c.QueryOne("select count(id) from users").Scan(&res)
var users []struct {
ID int `db:"id"`
Name string `db:"name"`
}
err := c.Query("select id, name from users where id in (?)", []int{1, 2}).Scan(&users)

Exec

affectedRows, err := c.Exec("delete from users where id != ?", 1)