-
Notifications
You must be signed in to change notification settings - Fork 2
/
objects.go
77 lines (61 loc) · 1.33 KB
/
objects.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
67
68
69
70
71
72
73
74
75
76
77
package gitquery
import (
"gopkg.in/sqle/sqle.v0/sql"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)
type objectsTable struct {
r *git.Repository
}
func newObjectsTable(r *git.Repository) sql.Table {
return &objectsTable{r: r}
}
func (objectsTable) Resolved() bool {
return true
}
func (objectsTable) Name() string {
return objectsTableName
}
func (objectsTable) Schema() sql.Schema {
return sql.Schema{
{Name: "id", Type: sql.String, Nullable: false},
{Name: "type", Type: sql.String, Nullable: false},
}
}
func (r *objectsTable) TransformUp(f func(sql.Node) sql.Node) sql.Node {
return f(r)
}
func (r *objectsTable) TransformExpressionsUp(f func(sql.Expression) sql.Expression) sql.Node {
return r
}
func (r objectsTable) RowIter() (sql.RowIter, error) {
oIter, err := r.r.Objects()
if err != nil {
return nil, err
}
iter := &objectIter{i: oIter}
return iter, nil
}
func (objectsTable) Children() []sql.Node {
return []sql.Node{}
}
type objectIter struct {
i *object.ObjectIter
}
func (i *objectIter) Next() (sql.Row, error) {
o, err := i.i.Next()
if err != nil {
return nil, err
}
return objectToRow(o), nil
}
func (i *objectIter) Close() error {
i.i.Close()
return nil
}
func objectToRow(o object.Object) sql.Row {
return sql.NewRow(
o.ID().String(),
o.Type().String(),
)
}