-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract.go
58 lines (49 loc) · 1.26 KB
/
extract.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
)
func extract(target *Target, extractChannel chan<- []map[string]interface{}) {
if target.prefetch == "" {
extractToChannel(target, target.params, extractChannel)
} else {
prefetch(target, extractChannel)
}
close(extractChannel)
}
func extractToChannel(target *Target, params []interface{}, extractChannel chan<- []map[string]interface{}) {
rows, err := target.connection.db.Query(target.extract, params...)
check(err)
defer rows.Close()
more := true
for more {
var data []map[string]interface{}
data, more, err = getRows(rows, args.nulls, args.page)
check(err)
applyTimezoneAll(target.location, data)
if len(data) > 0 {
extractChannel <- data
}
}
}
func extractIds(target *Target, ids []uint64) ([][]map[string]interface{}, error) {
query := fmt.Sprintf(target.extract, csv(ids))
rows, err := target.connection.db.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
result := make([][]map[string]interface{}, 0)
more := true
for more {
var data []map[string]interface{}
data, more, err = getRows(rows, args.nulls, args.page)
if err != nil {
return nil, err
}
applyTimezoneAll(target.location, data)
if len(data) > 0 {
result = append(result, data)
}
}
return result, nil
}