change rowObj var name to rowArray

This commit is contained in:
syumai 2024-04-27 15:34:02 +09:00
parent 2b25f7619a
commit 640a515c7b
2 changed files with 15 additions and 14 deletions

View File

@ -10,7 +10,7 @@ import (
)
type rows struct {
rowsObj js.Value
rowsArray js.Value
currentRow int
// columns is cached value of Columns method.
// do not use this directly.
@ -74,10 +74,11 @@ func (r *rows) Next(dest []driver.Value) error {
if r.currentRow == r.rowsLen() {
return io.EOF
}
rowObj := r.rowsObj.Index(r.currentRow)
rowObjLen := rowObj.Length()
for i := 0; i < rowObjLen; i++ {
v, err := convertRowColumnValueToAny(rowObj.Index(i))
// rowArray is Array of string.
rowArray := r.rowsArray.Index(r.currentRow)
rowArrayLen := rowArray.Length()
for i := 0; i < rowArrayLen; i++ {
v, err := convertRowColumnValueToAny(rowArray.Index(i))
if err != nil {
return err
}
@ -89,7 +90,7 @@ func (r *rows) Next(dest []driver.Value) error {
func (r *rows) rowsLen() int {
r.onceRowsLen.Do(func() {
r._rowsLen = r.rowsObj.Length()
r._rowsLen = r.rowsArray.Length()
})
return r._rowsLen
}

View File

@ -60,29 +60,29 @@ func (s *stmt) QueryContext(_ context.Context, args []driver.NamedValue) (driver
argValues[i] = arg.Value
}
resultPromise := s.stmtObj.Call("bind", argValues...).Call("raw", map[string]any{"columnNames": true})
rowsObj, err := jsutil.AwaitPromise(resultPromise)
rowsArray, err := jsutil.AwaitPromise(resultPromise)
if err != nil {
return nil, err
}
// If there are no rows to retrieve, length is 0.
if rowsObj.Length() == 0 {
if rowsArray.Length() == 0 {
return &rows{
columns: nil,
rowsObj: rowsObj,
columns: nil,
rowsArray: rowsArray,
}, nil
}
// The first result array includes the column names.
colsArray := rowsObj.Index(0)
colsArray := rowsArray.Index(0)
colsLen := colsArray.Length()
cols := make([]string, colsLen)
for i := 0; i < colsLen; i++ {
cols[i] = colsArray.Index(i).String()
}
// Remove the first result array from the rowsObj.
rowsObj.Call("shift")
rowsArray.Call("shift")
return &rows{
columns: cols,
rowsObj: rowsObj,
columns: cols,
rowsArray: rowsArray,
}, nil
}