-
Notifications
You must be signed in to change notification settings - Fork 2
/
blobs.go
77 lines (61 loc) · 1.29 KB
/
blobs.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 blobsTable struct {
r *git.Repository
}
func newBlobsTable(r *git.Repository) sql.Table {
return &blobsTable{r: r}
}
func (blobsTable) Resolved() bool {
return true
}
func (blobsTable) Name() string {
return blobsTableName
}
func (blobsTable) Schema() sql.Schema {
return sql.Schema{
{Name: "hash", Type: sql.String, Nullable: false},
{Name: "size", Type: sql.BigInteger, Nullable: false},
}
}
func (r *blobsTable) TransformUp(f func(sql.Node) sql.Node) sql.Node {
return f(r)
}
func (r *blobsTable) TransformExpressionsUp(f func(sql.Expression) sql.Expression) sql.Node {
return r
}
func (r blobsTable) RowIter() (sql.RowIter, error) {
bIter, err := r.r.BlobObjects()
if err != nil {
return nil, err
}
iter := &blobIter{i: bIter}
return iter, nil
}
func (blobsTable) Children() []sql.Node {
return []sql.Node{}
}
type blobIter struct {
i *object.BlobIter
}
func (i *blobIter) Next() (sql.Row, error) {
blob, err := i.i.Next()
if err != nil {
return nil, err
}
return blobToRow(blob), nil
}
func (i *blobIter) Close() error {
i.i.Close()
return nil
}
func blobToRow(c *object.Blob) sql.Row {
return sql.NewRow(
c.Hash.String(),
c.Size,
)
}