sqlx有一个很好的帮助:
In()我们只需要准备查询args和Rebind,如下所示:
var qids []int
// fills qids on query dynamically
query, args, err := sqlx.In("SELECT * FROM quote WHERE qid IN (?)", qids)
if err != nil {
log.Fatal(err)
}
// sqlx.In returns queries with the `?` bindvar, we can rebind it for our backend
//
query = database.SQL.Rebind(query) // database.SQL should be a *sqlx.DB
err = database.SQL.Select("es, query, args...)
if err != nil {
log.Fatal(err)
}
// or just in one line:
err = database.SQL.Select("es, database.SQL.Rebind(query), args...)