Skip to content

Commit

Permalink
Remove uncessary type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed Apr 13, 2019
1 parent 286e19f commit 920ff0d
Showing 1 changed file with 35 additions and 40 deletions.
75 changes: 35 additions & 40 deletions src/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,54 @@ func (p LineProcessor) ProcessLine(s string) string {
}

stmt, _ := sqlparser.Parse(s)
insert := stmt.(*sqlparser.Insert)

switch stmt := stmt.(type) {
case *sqlparser.Insert:
table := insert.Table.Name.String()

table := stmt.Table.Name.String()
processor := p.Config.ProcessTable(table)

processor := p.Config.ProcessTable(table)

switch processor {
case "":
// This table doesn't need to be processed
return s
case "table":
// "Classic" processing
rows := stmt.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := stmt.Columns[i].String()
switch processor {
case "":
// This table doesn't need to be processed
return s
case "table":
// "Classic" processing
rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := insert.Columns[i].String()

result, dataType := p.Config.ProcessColumn(table, column)
result, dataType := p.Config.ProcessColumn(table, column)

if !result {
continue
}
if !result {
continue
}

e.(*sqlparser.SQLVal).Val = []byte(p.Provider.Get(dataType))
e.(*sqlparser.SQLVal).Val = []byte(p.Provider.Get(dataType))

}
}
return sqlparser.String(stmt) + ";\n"
case "eav":
// EAV processing
var attributeId string
rows := stmt.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := stmt.Columns[i].String()
if column == "attribute_id" {
switch v := e.(type) {
case *sqlparser.SQLVal:
switch v.Type {
default:
attributeId = string(v.Val)
}
}
return sqlparser.String(insert) + ";\n"
case "eav":
// EAV processing
var attributeId string
rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := insert.Columns[i].String()
if column == "attribute_id" {
switch v := e.(type) {
case *sqlparser.SQLVal:
switch v.Type {
default:
attributeId = string(v.Val)
}
}
}
}

return "FOOO" + attributeId + "\n"
default:
return s
}

return "FOOO" + attributeId + "\n"
default:
return s
}
Expand Down

0 comments on commit 920ff0d

Please sign in to comment.