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 {
|
type rows struct {
|
||||||
rowsObj js.Value
|
rowsArray js.Value
|
||||||
currentRow int
|
currentRow int
|
||||||
// columns is cached value of Columns method.
|
// columns is cached value of Columns method.
|
||||||
// do not use this directly.
|
// do not use this directly.
|
||||||
@ -74,10 +74,11 @@ func (r *rows) Next(dest []driver.Value) error {
|
|||||||
if r.currentRow == r.rowsLen() {
|
if r.currentRow == r.rowsLen() {
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
rowObj := r.rowsObj.Index(r.currentRow)
|
// rowArray is Array of string.
|
||||||
rowObjLen := rowObj.Length()
|
rowArray := r.rowsArray.Index(r.currentRow)
|
||||||
for i := 0; i < rowObjLen; i++ {
|
rowArrayLen := rowArray.Length()
|
||||||
v, err := convertRowColumnValueToAny(rowObj.Index(i))
|
for i := 0; i < rowArrayLen; i++ {
|
||||||
|
v, err := convertRowColumnValueToAny(rowArray.Index(i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +90,7 @@ func (r *rows) Next(dest []driver.Value) error {
|
|||||||
|
|
||||||
func (r *rows) rowsLen() int {
|
func (r *rows) rowsLen() int {
|
||||||
r.onceRowsLen.Do(func() {
|
r.onceRowsLen.Do(func() {
|
||||||
r._rowsLen = r.rowsObj.Length()
|
r._rowsLen = r.rowsArray.Length()
|
||||||
})
|
})
|
||||||
return r._rowsLen
|
return r._rowsLen
|
||||||
}
|
}
|
||||||
|
@ -60,29 +60,29 @@ func (s *stmt) QueryContext(_ context.Context, args []driver.NamedValue) (driver
|
|||||||
argValues[i] = arg.Value
|
argValues[i] = arg.Value
|
||||||
}
|
}
|
||||||
resultPromise := s.stmtObj.Call("bind", argValues...).Call("raw", map[string]any{"columnNames": true})
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// If there are no rows to retrieve, length is 0.
|
// If there are no rows to retrieve, length is 0.
|
||||||
if rowsObj.Length() == 0 {
|
if rowsArray.Length() == 0 {
|
||||||
return &rows{
|
return &rows{
|
||||||
columns: nil,
|
columns: nil,
|
||||||
rowsObj: rowsObj,
|
rowsArray: rowsArray,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first result array includes the column names.
|
// The first result array includes the column names.
|
||||||
colsArray := rowsObj.Index(0)
|
colsArray := rowsArray.Index(0)
|
||||||
colsLen := colsArray.Length()
|
colsLen := colsArray.Length()
|
||||||
cols := make([]string, colsLen)
|
cols := make([]string, colsLen)
|
||||||
for i := 0; i < colsLen; i++ {
|
for i := 0; i < colsLen; i++ {
|
||||||
cols[i] = colsArray.Index(i).String()
|
cols[i] = colsArray.Index(i).String()
|
||||||
}
|
}
|
||||||
// Remove the first result array from the rowsObj.
|
// Remove the first result array from the rowsObj.
|
||||||
rowsObj.Call("shift")
|
rowsArray.Call("shift")
|
||||||
return &rows{
|
return &rows{
|
||||||
columns: cols,
|
columns: cols,
|
||||||
rowsObj: rowsObj,
|
rowsArray: rowsArray,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user