From 14a4b5e235d56380aa430e3ed9bae7f35d557003 Mon Sep 17 00:00:00 2001 From: Bill Moran Date: Wed, 1 May 2024 11:14:04 -0400 Subject: [PATCH] Factor away GlobalSqlParser --- lib/dbsteward.go | 2 +- lib/format/pgsql8/function.go | 2 +- lib/sql_parser.go | 22 +--------------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/lib/dbsteward.go b/lib/dbsteward.go index 8bd351e..fac6518 100644 --- a/lib/dbsteward.go +++ b/lib/dbsteward.go @@ -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) } diff --git a/lib/format/pgsql8/function.go b/lib/format/pgsql8/function.go index b96fd4c..6b88aae 100644 --- a/lib/format/pgsql8/function.go +++ b/lib/format/pgsql8/function.go @@ -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 } diff --git a/lib/sql_parser.go b/lib/sql_parser.go index 6138941..8cb0157 100644 --- a/lib/sql_parser.go +++ b/lib/sql_parser.go @@ -2,8 +2,6 @@ package lib import ( "strings" - - "github.com/dbsteward/dbsteward/lib/ir" ) // TODO(go,pgsql) move this to pgsql8/sql @@ -13,16 +11,7 @@ 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) @@ -30,12 +19,3 @@ func (parser *SqlParser) ParseQualifiedTableName(table string) QualifiedTable { } 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 "" -}