mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
29 lines
706 B
Go
29 lines
706 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package sqlstore
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// Converts a list of strings into a list of query parameters and a named parameter map that can
|
|
// be used as part of a SQL query.
|
|
func MapStringsToQueryParams(list []string, paramPrefix string) (string, map[string]interface{}) {
|
|
keys := bytes.Buffer{}
|
|
params := make(map[string]interface{}, len(list))
|
|
for i, entry := range list {
|
|
if keys.Len() > 0 {
|
|
keys.WriteString(",")
|
|
}
|
|
|
|
key := paramPrefix + strconv.Itoa(i)
|
|
keys.WriteString(":" + key)
|
|
params[key] = entry
|
|
}
|
|
|
|
return fmt.Sprintf("(%v)", keys.String()), params
|
|
}
|