From 640a515c7b1a2359477ecab073f3749486320828 Mon Sep 17 00:00:00 2001 From: syumai Date: Sat, 27 Apr 2024 15:34:02 +0900 Subject: [PATCH] change rowObj var name to rowArray --- cloudflare/d1/rows.go | 13 +++++++------ cloudflare/d1/stmt.go | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cloudflare/d1/rows.go b/cloudflare/d1/rows.go index 326b995..e14f3c1 100644 --- a/cloudflare/d1/rows.go +++ b/cloudflare/d1/rows.go @@ -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 } diff --git a/cloudflare/d1/stmt.go b/cloudflare/d1/stmt.go index c1c92e1..b7233a7 100644 --- a/cloudflare/d1/stmt.go +++ b/cloudflare/d1/stmt.go @@ -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 }