Last active
February 6, 2020 02:40
-
-
Save estenssoros/953e177461e0239ee8bcac4195736f66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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