-
Notifications
You must be signed in to change notification settings - Fork 111
/
catalog.go
76 lines (66 loc) · 1.98 KB
/
catalog.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
package drivers
import (
"context"
"fmt"
"time"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"google.golang.org/protobuf/proto"
)
// Constants representing the kinds of catalog objects.
type ObjectType int
const (
ObjectTypeUnspecified ObjectType = 0
ObjectTypeTable ObjectType = 1
ObjectTypeSource ObjectType = 2
ObjectTypeModel ObjectType = 3
ObjectTypeMetricsView ObjectType = 4
)
// CatalogStore is implemented by drivers capable of storing catalog info for a specific instance.
type CatalogStore interface {
FindEntries(ctx context.Context, instanceID string, t ObjectType) []*CatalogEntry
FindEntry(ctx context.Context, instanceID string, name string) (*CatalogEntry, bool)
CreateEntry(ctx context.Context, instanceID string, entry *CatalogEntry) error
UpdateEntry(ctx context.Context, instanceID string, entry *CatalogEntry) error
DeleteEntry(ctx context.Context, instanceID string, name string) error
}
// CatalogEntry represents one object in the catalog, such as a source.
type CatalogEntry struct {
Name string
Type ObjectType
Object proto.Message
Path string
Embedded bool
Parents []string
Children []string
CreatedOn time.Time
UpdatedOn time.Time
RefreshedOn time.Time
}
func (e *CatalogEntry) GetTable() *runtimev1.Table {
obj, ok := e.Object.(*runtimev1.Table)
if !ok {
panic(fmt.Errorf("entry '%s' is not a table", e.Name))
}
return obj
}
func (e *CatalogEntry) GetSource() *runtimev1.Source {
obj, ok := e.Object.(*runtimev1.Source)
if !ok {
panic(fmt.Errorf("entry '%s' is not a source", e.Name))
}
return obj
}
func (e *CatalogEntry) GetModel() *runtimev1.Model {
obj, ok := e.Object.(*runtimev1.Model)
if !ok {
panic(fmt.Errorf("entry '%s' is not a model", e.Name))
}
return obj
}
func (e *CatalogEntry) GetMetricsView() *runtimev1.MetricsView {
obj, ok := e.Object.(*runtimev1.MetricsView)
if !ok {
panic(fmt.Errorf("entry '%s' is not a metrics view", e.Name))
}
return obj
}