-
Notifications
You must be signed in to change notification settings - Fork 111
/
sql.go
44 lines (36 loc) · 1.06 KB
/
sql.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 sql
import (
"context"
"errors"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/fileutil"
"github.com/rilldata/rill/runtime/services/catalog/artifacts"
)
/**
* this package contains code to map an sql file to a catalog object
*/
type artifact struct{}
var NotSupported = errors.New("only model supported for sql")
func init() {
artifacts.Register(".sql", &artifact{})
}
func (r *artifact) DeSerialise(ctx context.Context, filePath string, blob string) (*drivers.CatalogEntry, error) {
name := fileutil.Stem(filePath)
return &drivers.CatalogEntry{
Type: drivers.ObjectTypeModel,
Object: &runtimev1.Model{
Name: name,
Sql: blob,
Dialect: runtimev1.Model_DIALECT_DUCKDB,
},
Name: name,
Path: filePath,
}, nil
}
func (r *artifact) Serialise(ctx context.Context, catalogObject *drivers.CatalogEntry) (string, error) {
if catalogObject.Type != drivers.ObjectTypeModel {
return "", NotSupported
}
return catalogObject.GetModel().Sql, nil
}