Skip to content

Commit

Permalink
Factor away GlobalSqlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
williammoran committed May 1, 2024
1 parent 233387b commit 14a4b5e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/dbsteward.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (self *DBSteward) ArgParse() {
self.OnlySchemaSql = args.OnlySchemaSql
self.OnlyDataSql = args.OnlyDataSql
for _, onlyTable := range args.OnlyTables {
table := GlobalSqlParser.ParseQualifiedTableName(onlyTable)
table := ParseQualifiedTableName(onlyTable)
self.LimitToTables[table.Schema] = append(self.LimitToTables[table.Schema], table.Table)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/format/pgsql8/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func functionDefinitionReferencesTable(definition *ir.FunctionDefinition) *lib.Q
if table == "" {
return nil
}
parsed := lib.GlobalSqlParser.ParseQualifiedTableName(table)
parsed := lib.ParseQualifiedTableName(table)
return &parsed
}

Expand Down
22 changes: 1 addition & 21 deletions lib/sql_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package lib

import (
"strings"

"github.com/dbsteward/dbsteward/lib/ir"
)

// TODO(go,pgsql) move this to pgsql8/sql
Expand All @@ -13,29 +11,11 @@ type QualifiedTable struct {
Table string
}

var GlobalSqlParser *SqlParser = NewSqlParser()

type SqlParser struct {
}

func NewSqlParser() *SqlParser {
return &SqlParser{}
}

func (parser *SqlParser) ParseQualifiedTableName(table string) QualifiedTable {
func ParseQualifiedTableName(table string) QualifiedTable {
// TODO(go,core) need to properly parse possible quoted names
if strings.Contains(table, ".") {
parts := strings.SplitN(table, ".", 2)
return QualifiedTable{parts[0], parts[1]}
}
return QualifiedTable{"public", table}
}

func (parser *SqlParser) GetSchemaName(name string) string {
return parser.ParseQualifiedTableName(name).Schema
}

func (parser *SqlParser) GetObjectName(name string, def *ir.Definition) string {
// TODO(go,core)
return ""
}

0 comments on commit 14a4b5e

Please sign in to comment.