| 104 | } |
| 105 | |
| 106 | func (s *PgStmt) Query(args []driver.Value) (driver.Rows, error) { |
| 107 | v, err := s.queryExec(args) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | |
| 112 | cols := v.Get("fields") |
| 113 | rows := v.Get("rows") |
| 114 | |
| 115 | cl := cols.Length() |
| 116 | rl := rows.Length() |
| 117 | |
| 118 | ret := rowsPool.Get().(*Rows) |
| 119 | *ret = zeroRows // wipe clean for reuse |
| 120 | |
| 121 | ret.useArray = (cl == 1 && rl == 1 && rows.Index(0).Length() == 1) |
| 122 | |
| 123 | if ret.useArray { |
| 124 | ret.colsA[0] = cols.Index(0).Get("name").String() |
| 125 | ret.rowsA[0][0] = colVal(rows.Index(0).Index(0)) |
| 126 | return ret, nil |
| 127 | } |
| 128 | |
| 129 | ret.cols = make([]string, cols.Length()) |
| 130 | ret.rows = make([][]interface{}, rows.Length()) |
| 131 | |
| 132 | rowLen := -1 |
| 133 | if rl != 0 && rows.Index(0).Length() != 0 { |
| 134 | rowLen = rows.Index(0).Length() |
| 135 | } |
| 136 | |
| 137 | for i := 0; i < len(ret.cols); i++ { |
| 138 | name := cols.Index(i).Get("name").String() |
| 139 | ret.cols[i] = name |
| 140 | } |
| 141 | |
| 142 | for i := 0; i < len(ret.rows); i++ { |
| 143 | row := rows.Index(i) |
| 144 | ret.rows[i] = make([]interface{}, rowLen) |
| 145 | |
| 146 | for j := 0; j < rowLen; j++ { |
| 147 | ret.rows[i][j] = colVal(row.Index(j)) |
| 148 | } |
| 149 | } |
| 150 | return ret, nil |
| 151 | } |
| 152 | |
| 153 | func getPGTypeParser() map[string]interface{} { |
| 154 | fn := js.FuncOf(func(this js.Value, args []js.Value) interface{} { |