Skip to content

Commit

Permalink
[fix] reuse code in ExecSQL and ExecSQLToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jan 9, 2019
1 parent ccb0a6e commit 5c8ba62
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions reindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,24 +492,21 @@ func (db *Reindexer) Query(namespace string) *Query {
return newQuery(db, namespace)
}

// ExecSQL make query to database. Query is SQL statement
// Return Iterator
// ExecSQL make query to database. Query is a SQL statement.
// Return Iterator.
func (db *Reindexer) ExecSQL(query string) *Iterator {
// TODO: do not parse query string twice in go and cpp
namespace := ""
querySlice := strings.Fields(strings.ToLower(query))

for i := range querySlice {
if querySlice[i] == "from" && i+1 < len(querySlice) {
namespace = querySlice[i+1]
break
}
}

namespace := getQueryNamespace(query)
return db.execSQL(namespace, query)
}

// ExecSQLToJSON make query to database. Query is a SQL statement.
// Return JSONIterator.
func (db *Reindexer) ExecSQLToJSON(query string) *JSONIterator {
namespace := getQueryNamespace(query)
return db.execSQLAsJSON(namespace, query)
}

func getQueryNamespace(query string) string {
// TODO: do not parse query string twice in go and cpp
namespace := ""
querySlice := strings.Fields(strings.ToLower(query))
Expand All @@ -520,8 +517,7 @@ func (db *Reindexer) ExecSQLToJSON(query string) *JSONIterator {
break
}
}

return db.execSQLAsJSON(namespace, query)
return namespace
}

// BeginTx - start update transaction
Expand Down

0 comments on commit 5c8ba62

Please sign in to comment.