-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
66 lines (57 loc) · 1.35 KB
/
main.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
59
60
61
62
63
64
65
66
package main
import (
"bufio"
"flag"
"log"
"os"
"strconv"
"strings"
"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/bolt"
"github.com/cayleygraph/cayley/quad"
)
func main() {
dbFile := flag.String("db", "db", "BoltDB file")
csvFile := flag.String("csv", "pokemon.csv", "csv file with pokemon")
flag.Parse()
// Initialize the database
graph.InitQuadStore("bolt", *dbFile, nil)
// Open and use the database
store, err := cayley.NewGraph("bolt", *dbFile, nil)
if err != nil {
log.Fatalln(err)
}
file, err := os.Open(*csvFile)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := strings.Split(scanner.Text(), ",")
id, err := strconv.Atoi(s[0])
if err != nil {
log.Fatal(err)
}
speciesId, err := strconv.Atoi(s[2])
if err != nil {
log.Fatal(err)
}
height, err := strconv.Atoi(s[3])
if err != nil {
log.Fatal(err)
}
baseExperience, err := strconv.Atoi(s[4])
if err != nil {
log.Fatal(err)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
store.AddQuad(quad.Make(id, "name", s[1], "."))
store.AddQuad(quad.Make(id, "species_id", speciesId, "."))
store.AddQuad(quad.Make(id, "height", height, "."))
store.AddQuad(quad.Make(id, "base_experience", baseExperience, "."))
}
}