mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
change rowObj var name to rowArray
This commit is contained in:
parent
2b25f7619a
commit
640a515c7b
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user