Skip to content

Commit 06ca553

Browse files
committed
feat(statement-result): populate query field on success
1 parent 675c70d commit 06ca553

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/db/db.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ type StatementResult struct {
4545
Query string
4646
}
4747

48-
func newStatementResult(columnNames []string, rowCh chan rowResult) *StatementResult {
49-
return &StatementResult{ColumnNames: columnNames, RowCh: rowCh}
48+
func newStatementResult(columnNames []string, rowCh chan rowResult, query string) *StatementResult {
49+
return &StatementResult{ColumnNames: columnNames, RowCh: rowCh, Query: query}
5050
}
5151

5252
func newStatementResultWithError(err error) *StatementResult {
@@ -173,7 +173,7 @@ func (db *Db) executeQuery(query string, statementResultCh chan StatementResult)
173173

174174
defer rows.Close()
175175

176-
return readQueryResults(rows, statementResultCh)
176+
return readQueryResults(rows, statementResultCh, query)
177177
}
178178

179179
func (db *Db) prepareStatementsIntoQueries(statementsString string) []string {
@@ -221,10 +221,10 @@ func getColumnTypes(rows *sql.Rows) ([]reflect.Type, error) {
221221
return types, nil
222222
}
223223

224-
func readQueryResults(queryRows *sql.Rows, statementResultCh chan StatementResult) (shouldContinue bool) {
224+
func readQueryResults(queryRows *sql.Rows, statementResultCh chan StatementResult, query string) (shouldContinue bool) {
225225
hasResultSetToRead := true
226226
for hasResultSetToRead {
227-
if shouldContinue := readQueryResultSet(queryRows, statementResultCh); !shouldContinue {
227+
if shouldContinue := readQueryResultSet(queryRows, statementResultCh, query); !shouldContinue {
228228
return false
229229
}
230230

@@ -239,7 +239,7 @@ func readQueryResults(queryRows *sql.Rows, statementResultCh chan StatementResul
239239
return true
240240
}
241241

242-
func readQueryResultSet(queryRows *sql.Rows, statementResultCh chan StatementResult) (shouldContinue bool) {
242+
func readQueryResultSet(queryRows *sql.Rows, statementResultCh chan StatementResult, query string) (shouldContinue bool) {
243243
columnNames, err := getColumnNames(queryRows)
244244
if err != nil {
245245
statementResultCh <- *newStatementResultWithError(err)
@@ -265,7 +265,7 @@ func readQueryResultSet(queryRows *sql.Rows, statementResultCh chan StatementRes
265265
rowCh := make(chan rowResult)
266266
defer close(rowCh)
267267

268-
statementResultCh <- *newStatementResult(columnNames, rowCh)
268+
statementResultCh <- *newStatementResult(columnNames, rowCh, query)
269269

270270
for queryRows.Next() {
271271
err = queryRows.Scan(columnPointers...)

0 commit comments

Comments
 (0)