generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract databases in Kotlin schema
- Loading branch information
Showing
13 changed files
with
816 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package schema | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"google.golang.org/protobuf/proto" | ||
|
||
schemapb "github.com/TBD54566975/ftl/protos/xyz/block/ftl/v1/schema" | ||
) | ||
|
||
type Database struct { | ||
Pos Position `parser:"" protobuf:"1,optional"` | ||
|
||
Comments []string `parser:"@Comment*" protobuf:"3"` | ||
Name string `parser:"'database' @Ident" protobuf:"2"` | ||
} | ||
|
||
var _ Decl = (*Database)(nil) | ||
|
||
// schemaDecl implements Decl | ||
func (*Database) schemaDecl() {} | ||
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", d.Name) | ||
return w.String() | ||
} | ||
|
||
func (d *Database) ToProto() proto.Message { | ||
return &schemapb.Database{ | ||
Pos: posToProto(d.Pos), | ||
Name: d.Name, | ||
Comments: d.Comments, | ||
} | ||
} | ||
func DatabaseToSchema(s *schemapb.Database) *Database { | ||
return &Database{ | ||
Pos: posFromProto(s.Pos), | ||
Name: s.Name, | ||
Comments: s.Comments, | ||
} | ||
} | ||
|
||
func databaseListToSchema(s []*schemapb.Database) []*Database { | ||
var out []*Database | ||
for _, n := range s { | ||
out = append(out, DatabaseToSchema(n)) | ||
} | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package schema | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"google.golang.org/protobuf/proto" | ||
|
||
schemapb "github.com/TBD54566975/ftl/protos/xyz/block/ftl/v1/schema" | ||
) | ||
|
||
type MetadataDatabases struct { | ||
Pos Position `parser:"" protobuf:"1,optional"` | ||
|
||
Calls []*Database `parser:"'database' 'calls' @@ (',' @@)*" protobuf:"2"` | ||
} | ||
|
||
var _ Metadata = (*MetadataDatabases)(nil) | ||
|
||
func (m *MetadataDatabases) String() string { | ||
out := &strings.Builder{} | ||
fmt.Fprint(out, "database calls ") | ||
w := 6 | ||
for i, call := range m.Calls { | ||
if i > 0 { | ||
fmt.Fprint(out, ", ") | ||
w += 2 | ||
} | ||
str := call.String() | ||
if w+len(str) > 70 { | ||
w = 6 | ||
fmt.Fprint(out, "\n ") | ||
} | ||
w += len(str) | ||
fmt.Fprint(out, str) | ||
} | ||
fmt.Fprintln(out) | ||
return out.String() | ||
} | ||
|
||
func (m *MetadataDatabases) schemaChildren() []Node { | ||
out := make([]Node, 0, len(m.Calls)) | ||
for _, ref := range m.Calls { | ||
out = append(out, ref) | ||
} | ||
return out | ||
} | ||
func (*MetadataDatabases) schemaMetadata() {} | ||
|
||
func (m *MetadataDatabases) ToProto() proto.Message { | ||
return &schemapb.MetadataDatabases{ | ||
Pos: posToProto(m.Pos), | ||
Calls: nodeListToProto[*schemapb.Database](m.Calls), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
frontend/src/protos/xyz/block/ftl/v1/schema/schema_pb.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.