Skip to content

Instantly share code, notes, and snippets.

@estenssoros
Last active February 6, 2020 02:40
Show Gist options
  • Save estenssoros/953e177461e0239ee8bcac4195736f66 to your computer and use it in GitHub Desktop.
Save estenssoros/953e177461e0239ee8bcac4195736f66 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
)
type model struct {
ID int
}
func joinIds(models []model) string {
ids := make([]string, len(models))
for i := 0; i < len(models); i++ {
ids[i] = fmt.Sprint(models[i].id)
}
return strings.Join(models, ",")
}
func run() {
models := []model{}
query := "SELECT id FROM blah WHERE id in (%s)"
rows, err:= db.Query(fmt.Sprintf(query, joinIds(models))
...
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment