forked from t-tiger/gorm-bulk-insert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
39 lines (33 loc) · 801 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gormbulk
import "sort"
// Separate objects into several size
func splitObjects(objArr []interface{}, size int) [][]interface{} {
var chunkSet [][]interface{}
var chunk []interface{}
for len(objArr) > size {
chunk, objArr = objArr[:size], objArr[size:]
chunkSet = append(chunkSet, chunk)
}
if len(objArr) > 0 {
chunkSet = append(chunkSet, objArr[:])
}
return chunkSet
}
// Enable map keys to be retrieved in same order when iterating
func sortedKeys(val map[string]interface{}) []string {
var keys []string
for key := range val {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}
// Check if string value is contained in slice
func containString(s []string, value string) bool {
for _, v := range s {
if v == value {
return true
}
}
return false
}