diff --git a/cloudflare/d1/rows.go b/cloudflare/d1/rows.go index e14f3c1..76c3f81 100644 --- a/cloudflare/d1/rows.go +++ b/cloudflare/d1/rows.go @@ -12,9 +12,9 @@ import ( type rows struct { rowsArray js.Value currentRow int - // columns is cached value of Columns method. + // _columns is cached value of Columns method. // do not use this directly. - columns []string + _columns []string // _rowsLen is cached value of rowsLen method. // do not use this directly. _rowsLen int @@ -27,7 +27,7 @@ var _ driver.Rows = (*rows)(nil) // Columns returns column names retrieved from query result. // If rows are empty, this returns nil. func (r *rows) Columns() []string { - return r.columns + return r._columns } func (r *rows) Close() error { diff --git a/cloudflare/d1/stmt.go b/cloudflare/d1/stmt.go index b7233a7..fe2cc1b 100644 --- a/cloudflare/d1/stmt.go +++ b/cloudflare/d1/stmt.go @@ -67,22 +67,20 @@ func (s *stmt) QueryContext(_ context.Context, args []driver.NamedValue) (driver // If there are no rows to retrieve, length is 0. if rowsArray.Length() == 0 { return &rows{ - columns: nil, + _columns: nil, rowsArray: rowsArray, }, nil } - // The first result array includes the column names. - colsArray := rowsArray.Index(0) + // First item of rowsArray is column names + colsArray := rowsArray.Call("shift") 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. - rowsArray.Call("shift") return &rows{ - columns: cols, + _columns: cols, rowsArray: rowsArray, }, nil }