-
Notifications
You must be signed in to change notification settings - Fork 62
Using with Other Packages
Mario Gutierrez edited this page Jun 21, 2015
·
1 revision
import "github.com/mgutz/dat.v1"
builder := dat.Select("*").From("posts").Where("user_id = $1", 1)
// Get builder's SQL and arguments
sql, args := builder.ToSQL()
fmt.Println(sql) // SELECT * FROM posts WHERE (user_id = $1)
fmt.Println(args) // [1]
// Use raw database/sql for actual query
rows, err := db.Query(sql, args...)
// Alternatively build the interpolated sql statement
sql, args, err := builder.Interpolate()
if len(args) == 0 {
rows, err = db.Query(sql)
} else {
rows, err = db.Query(sql, args...)
}