generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
database.go
55 lines (44 loc) · 1.33 KB
/
database.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
package schema
import (
"fmt"
"strings"
"google.golang.org/protobuf/proto"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)
const PostgresDatabaseType = "postgres"
type Database struct {
Pos Position `parser:"" protobuf:"1,optional"`
Comments []string `parser:"@Comment*" protobuf:"2"`
Type string `parser:"'database' @'postgres'" protobuf:"4"`
Name string `parser:"@Ident" protobuf:"3"`
}
var _ Decl = (*Database)(nil)
var _ Symbol = (*Database)(nil)
func (d *Database) Position() Position { return d.Pos }
func (*Database) schemaDecl() {}
func (*Database) schemaSymbol() {}
func (d *Database) schemaChildren() []Node { return nil }
func (d *Database) String() string {
w := &strings.Builder{}
fmt.Fprint(w, EncodeComments(d.Comments))
fmt.Fprintf(w, "database %s %s", d.Type, d.Name)
return w.String()
}
func (d *Database) ToProto() proto.Message {
return &schemapb.Database{
Pos: posToProto(d.Pos),
Comments: d.Comments,
Name: d.Name,
Type: d.Type,
}
}
func (d *Database) GetName() string { return d.Name }
func (d *Database) IsExported() bool { return false }
func DatabaseFromProto(s *schemapb.Database) *Database {
return &Database{
Pos: posFromProto(s.Pos),
Comments: s.Comments,
Name: s.Name,
Type: s.Type,
}
}