github.com/jfrerich/mattermost-server@v5.8.0-rc2+incompatible/store/sqlstore/utils.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package sqlstore 5 6 import ( 7 "bytes" 8 "fmt" 9 "strconv" 10 ) 11 12 // Converts a list of strings into a list of query parameters and a named parameter map that can 13 // be used as part of a SQL query. 14 func MapStringsToQueryParams(list []string, paramPrefix string) (string, map[string]interface{}) { 15 keys := bytes.Buffer{} 16 params := make(map[string]interface{}, len(list)) 17 for i, entry := range list { 18 if keys.Len() > 0 { 19 keys.WriteString(",") 20 } 21 22 key := paramPrefix + strconv.Itoa(i) 23 keys.WriteString(":" + key) 24 params[key] = entry 25 } 26 27 return fmt.Sprintf("(%v)", keys.String()), params 28 }