Skip to content

Commit

Permalink
ToModel() -> ToIR() for consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
williammoran committed Apr 19, 2024
1 parent bb1efcb commit 4a8c1d6
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lib/encoding/xml/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (self *Column) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) e
return nil
}

func (col *Column) ToModel() (*ir.Column, error) {
func (col *Column) ToIR() (*ir.Column, error) {
// skipping DEPRICATED fields
rv := ir.Column{
Name: col.Name,
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/xml/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Constraint struct {
ForeignTable string `xml:"foreignTable,attr,omitempty"`
}

func (c *Constraint) ToModel() (*ir.Constraint, error) {
func (c *Constraint) ToIR() (*ir.Constraint, error) {
rv := ir.Constraint{
Name: c.Name,
Definition: c.Definition,
Expand Down
10 changes: 5 additions & 5 deletions lib/encoding/xml/data_rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type DataRows struct {
TabRows []string `xml:"tabrow"`
}

func (dr *DataRows) ToModel() (*ir.DataRows, error) {
func (dr *DataRows) ToIR() (*ir.DataRows, error) {
if dr == nil {
return nil, nil
}
Expand All @@ -25,7 +25,7 @@ func (dr *DataRows) ToModel() (*ir.DataRows, error) {
TabRows: dr.TabRows,
}
for _, row := range dr.Rows {
nRow, err := row.ToModel()
nRow, err := row.ToIR()
if err != nil {
return nil, err
}
Expand All @@ -39,15 +39,15 @@ type DataRow struct {
Delete bool `xml:"delete,attr,omitempty"` // TODO(go,core) does this un/marshal properly?
}

func (dr *DataRow) ToModel() (*ir.DataRow, error) {
func (dr *DataRow) ToIR() (*ir.DataRow, error) {
if dr == nil {
return nil, nil
}
rv := ir.DataRow{
Delete: dr.Delete,
}
for _, dc := range dr.Columns {
nDC, err := dc.ToModel()
nDC, err := dc.ToIR()
if err != nil {
return nil, err
}
Expand All @@ -63,7 +63,7 @@ type DataCol struct {
Text string `xml:",chardata"`
}

func (dc *DataCol) ToModel() (*ir.DataCol, error) {
func (dc *DataCol) ToIR() (*ir.DataCol, error) {
if dc == nil {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/xml/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ConfigParam struct {
Value string `xml:"value,attr"`
}

func (db *Database) ToModel() (*ir.Database, error) {
func (db *Database) ToIR() (*ir.Database, error) {
if db == nil {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/xml/datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ type DataTypeDomainConstraint struct {
Check string `xml:",chardata"`
}

func (self *DataType) ToModel() (*ir.DataType, error) {
func (self *DataType) ToIR() (*ir.DataType, error) {
panic("todo")
}
22 changes: 11 additions & 11 deletions lib/encoding/xml/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,38 @@ type Sql struct {
Text string `xml:",chardata"`
}

// ToModel converts this Document to a ir.Definition, if possible.
// ToIR converts this Document to a ir.Definition, if possible.
//
// Errors may arise if this operation cannot be completed for some reason.
// No semantic validation is performed at this point, as that's outside
// of the scope of an "xml" package - see `ir.Definition.Validate()`
func (self *Document) ToModel() (*ir.Definition, error) {
includeFiles, err := util.MapErr(self.IncludeFiles, (*IncludeFile).ToModel)
func (self *Document) ToIR() (*ir.Definition, error) {
includeFiles, err := util.MapErr(self.IncludeFiles, (*IncludeFile).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process includeFile tags")
}

inlineAssembly, err := util.MapErr(self.InlineAssembly, (*InlineAssembly).ToModel)
inlineAssembly, err := util.MapErr(self.InlineAssembly, (*InlineAssembly).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process inlineAssembly tags")
}

database, err := self.Database.ToModel()
database, err := self.Database.ToIR()
if err != nil {
return nil, errors.Wrap(err, "could not process database tag")
}

schemas, err := util.MapErr(self.Schemas, (*Schema).ToModel)
schemas, err := util.MapErr(self.Schemas, (*Schema).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema tags")
}

languages, err := util.MapErr(self.Languages, (*Language).ToModel)
languages, err := util.MapErr(self.Languages, (*Language).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process language tags")
}

sql, err := util.MapErr(self.Sql, (*Sql).ToModel)
sql, err := util.MapErr(self.Sql, (*Sql).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process sql tags")
}
Expand All @@ -91,14 +91,14 @@ func (self *Document) FromModel(def *ir.Definition) error {
}

// TODO should there be a ir.IncludeFile, or should we always overlay when converting to model?
func (self *IncludeFile) ToModel() (*ir.IncludeFile, error) {
func (self *IncludeFile) ToIR() (*ir.IncludeFile, error) {
return &ir.IncludeFile{Name: self.Name}, nil
}

func (self *InlineAssembly) ToModel() (*ir.InlineAssembly, error) {
func (self *InlineAssembly) ToIR() (*ir.InlineAssembly, error) {
return &ir.InlineAssembly{Name: self.Name}, nil
}

func (self *Sql) ToModel() (*ir.Sql, error) {
func (self *Sql) ToIR() (*ir.Sql, error) {
panic("todo")
}
2 changes: 1 addition & 1 deletion lib/encoding/xml/foreignkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ForeignKey struct {
OnDelete string `xml:"onDelete,attr,omitempty"`
}

func (fk *ForeignKey) ToModel() (*ir.ForeignKey, error) {
func (fk *ForeignKey) ToIR() (*ir.ForeignKey, error) {
rv := ir.ForeignKey{
Columns: fk.Columns,
ForeignSchema: fk.ForeignSchema,
Expand Down
12 changes: 6 additions & 6 deletions lib/encoding/xml/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FunctionParameter struct {
Direction string `xml:"direction,attr,omitempty"`
}

func (fp *FunctionParameter) ToModel() (*ir.FunctionParameter, error) {
func (fp *FunctionParameter) ToIR() (*ir.FunctionParameter, error) {
if fp == nil {
return nil, nil
}
Expand All @@ -48,7 +48,7 @@ type FunctionDefinition struct {
Text string `xml:",cdata"`
}

func (fd *FunctionDefinition) ToModel() (*ir.FunctionDefinition, error) {
func (fd *FunctionDefinition) ToIR() (*ir.FunctionDefinition, error) {
if fd == nil {
return nil, nil
}
Expand All @@ -64,7 +64,7 @@ func (fd *FunctionDefinition) ToModel() (*ir.FunctionDefinition, error) {
return &rv, nil
}

func (f *Function) ToModel() (*ir.Function, error) {
func (f *Function) ToIR() (*ir.Function, error) {
if f == nil {
return nil, nil
}
Expand All @@ -78,21 +78,21 @@ func (f *Function) ToModel() (*ir.Function, error) {
SecurityDefiner: f.SecurityDefiner,
}
for _, p := range f.Parameters {
np, err := p.ToModel()
np, err := p.ToIR()
if err != nil {
return nil, fmt.Errorf("function '%s' invalid: %w", f.Name, err)
}
rv.Parameters = append(rv.Parameters, np)
}
for _, d := range f.Definitions {
nd, err := d.ToModel()
nd, err := d.ToIR()
if err != nil {
return nil, fmt.Errorf("function '%s' invalid: %w", f.Name, err)
}
rv.Definitions = append(rv.Definitions, nd)
}
for _, g := range f.Grants {
ng, err := g.ToModel()
ng, err := g.ToIR()
if err != nil {
return nil, fmt.Errorf("function '%s' invalid: %w", f.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/xml/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Grant struct {
With string `xml:"with,attr,omitempty"`
}

func (g *Grant) ToModel() (*ir.Grant, error) {
func (g *Grant) ToIR() (*ir.Grant, error) {
rv := ir.Grant{
Roles: g.Roles,
Permissions: g.Permissions,
Expand Down
10 changes: 5 additions & 5 deletions lib/encoding/xml/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type IndexDim struct {
Value string `xml:",chardata"`
}

func (id *IndexDim) ToModel() (*ir.IndexDim, error) {
func (id *IndexDim) ToIR() (*ir.IndexDim, error) {
return &ir.IndexDim{
Name: id.Name,
Sql: id.Sql,
Expand All @@ -36,7 +36,7 @@ type IndexCond struct {
Condition string `xml:",chardata"`
}

func (id *IndexCond) ToModel() (*ir.IndexCond, error) {
func (id *IndexCond) ToIR() (*ir.IndexCond, error) {
rv := ir.IndexCond{
Condition: id.Condition,
}
Expand All @@ -48,7 +48,7 @@ func (id *IndexCond) ToModel() (*ir.IndexCond, error) {
return &rv, nil
}

func (idx *Index) ToModel() (*ir.Index, error) {
func (idx *Index) ToIR() (*ir.Index, error) {
rv := ir.Index{
Name: idx.Name,
Unique: idx.Unique,
Expand All @@ -60,14 +60,14 @@ func (idx *Index) ToModel() (*ir.Index, error) {
return nil, fmt.Errorf("index '%s' invalid: %s", idx.Name, err)
}
for _, d := range idx.Dimensions {
nd, err := d.ToModel()
nd, err := d.ToIR()
if err != nil {
return nil, fmt.Errorf("index '%s' invalid: %s", idx.Name, err)
}
rv.Dimensions = append(rv.Dimensions, nd)
}
for _, c := range idx.Conditions {
nc, err := c.ToModel()
nc, err := c.ToIR()
if err != nil {
return nil, fmt.Errorf("index '%s' invalid: %s", idx.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/xml/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ type Language struct {
Validator string `xml:"validator,attr,omitempty"`
}

func (self *Language) ToModel() (*ir.Language, error) {
func (self *Language) ToIR() (*ir.Language, error) {
panic("todo")
}
10 changes: 5 additions & 5 deletions lib/encoding/xml/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type TablePartition struct {
Segments []*TablePartitionSegment `xml:"tablePartitionSegment"`
}

func (tp *TablePartition) ToModel() (*ir.TablePartition, error) {
func (tp *TablePartition) ToIR() (*ir.TablePartition, error) {
if tp == nil {
return nil, nil
}
Expand All @@ -28,10 +28,10 @@ func (tp *TablePartition) ToModel() (*ir.TablePartition, error) {
return nil, fmt.Errorf("inavalid table partition: %w", err)
}
for _, opt := range tp.Options {
rv.Options = append(rv.Options, opt.ToModel())
rv.Options = append(rv.Options, opt.ToIR())
}
for _, seg := range tp.Segments {
rv.Segments = append(rv.Segments, seg.ToModel())
rv.Segments = append(rv.Segments, seg.ToIR())
}
return &rv, nil
}
Expand All @@ -41,7 +41,7 @@ type TablePartitionOption struct {
Value string `xml:"value,attr"`
}

func (tpo *TablePartitionOption) ToModel() *ir.TablePartitionOption {
func (tpo *TablePartitionOption) ToIR() *ir.TablePartitionOption {
return &ir.TablePartitionOption{
Name: tpo.Name,
Value: tpo.Value,
Expand All @@ -53,7 +53,7 @@ type TablePartitionSegment struct {
Value string `xml:"value,attr"`
}

func (seg *TablePartitionSegment) ToModel() *ir.TablePartitionSegment {
func (seg *TablePartitionSegment) ToIR() *ir.TablePartitionSegment {
return &ir.TablePartitionSegment{
Name: seg.Name,
Value: seg.Value,
Expand Down
16 changes: 8 additions & 8 deletions lib/encoding/xml/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ type Schema struct {
Views []*View `xml:"view"`
}

func (self *Schema) ToModel() (*ir.Schema, error) {
tables, err := util.MapErr(self.Tables, (*Table).ToModel)
func (self *Schema) ToIR() (*ir.Schema, error) {
tables, err := util.MapErr(self.Tables, (*Table).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema table tags")
}
grants, err := util.MapErr(self.Grants, (*Grant).ToModel)
grants, err := util.MapErr(self.Grants, (*Grant).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema grant tags")
}
types, err := util.MapErr(self.Types, (*DataType).ToModel)
types, err := util.MapErr(self.Types, (*DataType).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema type tags")
}
sequences, err := util.MapErr(self.Sequences, (*Sequence).ToModel)
sequences, err := util.MapErr(self.Sequences, (*Sequence).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema sequence tags")
}
functions, err := util.MapErr(self.Functions, (*Function).ToModel)
functions, err := util.MapErr(self.Functions, (*Function).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema function tags")
}
triggers, err := util.MapErr(self.Triggers, (*Trigger).ToModel)
triggers, err := util.MapErr(self.Triggers, (*Trigger).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema trigger tags")
}
views, err := util.MapErr(self.Views, (*View).ToModel)
views, err := util.MapErr(self.Views, (*View).ToIR)
if err != nil {
return nil, errors.Wrap(err, "could not process schema view tags")
}
Expand Down
4 changes: 2 additions & 2 deletions lib/encoding/xml/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Sequence struct {
Grants []*Grant `xml:"grant"`
}

func (s *Sequence) ToModel() (*ir.Sequence, error) {
func (s *Sequence) ToIR() (*ir.Sequence, error) {
rv := ir.Sequence{
Name: s.Name,
Owner: s.Owner,
Expand All @@ -38,7 +38,7 @@ func (s *Sequence) ToModel() (*ir.Sequence, error) {
}

for _, g := range s.Grants {
ng, err := g.ToModel()
ng, err := g.ToIR()
if err != nil {
return nil, fmt.Errorf("sequence '%s' invalid: %w", s.Name, err)
}
Expand Down
Loading

0 comments on commit 4a8c1d6

Please sign in to comment.