-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.go
44 lines (38 loc) · 897 Bytes
/
get.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
package styx
import (
rdf "github.com/underlay/go-rdfjs"
)
// Get a dataset from the database
func (s *Store) Get(node rdf.Term) ([]*rdf.Quad, error) {
dictionary := s.Config.Dictionary.Open(false)
defer func() { dictionary.Commit() }()
id, err := dictionary.GetID(node, rdf.Default)
if err != nil {
return nil, err
}
quads, err := s.Config.QuadStore.Get(id)
if err != nil {
return nil, err
}
dataset := make([]*rdf.Quad, len(quads))
for i, quad := range quads {
s, err := dictionary.GetTerm(quad[0], node)
if err != nil {
return nil, err
}
p, err := dictionary.GetTerm(quad[1], node)
if err != nil {
return nil, err
}
o, err := dictionary.GetTerm(quad[2], node)
if err != nil {
return nil, err
}
g, err := dictionary.GetTerm(quad[3], node)
if err != nil {
return nil, err
}
dataset[i] = rdf.NewQuad(s, p, o, g)
}
return dataset, nil
}