mgutz / dat

Go Postgres Data Access Toolkit
Other
612 stars 62 forks source link

IN queries and MustInterpolate #50

Closed quetz closed 7 years ago

quetz commented 7 years ago

I'm using v2 version of dat and MustInterpolate is mentioned only in documentation, I can't find it anywhere in the code. And without it queries end up with $brj$ spliced in.

What's correct way of doing IN queries and what project branch is most actively developed at the moment?

mgutz commented 7 years ago

dat.EnableInterpolate = true would be the way to turn it on in an init function

Use gopkg.in/mgutz/dat.v2

quetz commented 7 years ago

I'm using code at commit 494217c and MustInterpolate is mentioned only in README.md but nowhere in code. Must be wrong branch or something...

mgutz commented 7 years ago

The README is inaccurate, my apologies. I removed that a while back favoring error values instead of panicking. The next version removes almost all panics.

If you want to use Interpolate directly.

sql, args, err := dat.Interpolate("select * from users where id IN $1", []int64{1, 2, 3})
if err != nil {
    return nil, err
}
var users []*User
_, err = DB.SQL(sql, args).QueryStructs(&users)
quetz commented 7 years ago

Thanks, that works!