|
1 | 1 | import WebSocket from 'ws'; |
2 | 2 | import * as flatbuffers from 'flatbuffers'; |
| 3 | +import { v4 as uuidv4 } from 'uuid'; |
3 | 4 | import { InlineTable } from '@cubejs-backend/base-driver'; |
4 | 5 | import { getEnv } from '@cubejs-backend/shared'; |
5 | | -import { v4 as uuidv4 } from 'uuid'; |
| 6 | +import { parseCubestoreResultMessage } from '@cubejs-backend/native'; |
6 | 7 | import { |
7 | 8 | HttpCommand, |
8 | | - HttpError, |
9 | 9 | HttpMessage, |
10 | 10 | HttpQuery, |
11 | | - HttpResultSet, |
12 | 11 | HttpTable |
13 | 12 | } from '../codegen'; |
14 | 13 |
|
@@ -116,44 +115,12 @@ export class WebSocketConnection { |
116 | 115 | if (!resolvers) { |
117 | 116 | throw new Error(`Cube Store missed message id: ${httpMessage.messageId()}`); // logging |
118 | 117 | } |
119 | | - const commandType = httpMessage.commandType(); |
120 | | - if (commandType === HttpCommand.HttpError) { |
121 | | - resolvers.reject(new Error(`${httpMessage.command(new HttpError())?.error()}`)); |
122 | | - } else if (commandType === HttpCommand.HttpResultSet) { |
123 | | - const resultSet = httpMessage.command(new HttpResultSet()); |
124 | | - if (!resultSet) { |
125 | | - resolvers.reject(new Error('Empty resultSet')); |
126 | | - return; |
127 | | - } |
128 | | - const columnsLen = resultSet.columnsLength(); |
129 | | - const columns: Array<string> = []; |
130 | | - for (let i = 0; i < columnsLen; i++) { |
131 | | - const columnName = resultSet.columns(i); |
132 | | - if (!columnName) { |
133 | | - resolvers.reject(new Error('Column name is not defined')); |
134 | | - return; |
135 | | - } |
136 | | - columns.push(columnName); |
137 | | - } |
138 | | - const rowLen = resultSet.rowsLength(); |
139 | | - const result: any[] = []; |
140 | | - for (let i = 0; i < rowLen; i++) { |
141 | | - const row = resultSet.rows(i); |
142 | | - if (!row) { |
143 | | - resolvers.reject(new Error('Null row')); |
144 | | - return; |
145 | | - } |
146 | | - const valueLen = row.valuesLength(); |
147 | | - const rowObj = {}; |
148 | | - for (let j = 0; j < valueLen; j++) { |
149 | | - const value = row.values(j); |
150 | | - rowObj[columns[j]] = value?.stringValue(); |
151 | | - } |
152 | | - result.push(rowObj); |
153 | | - } |
154 | | - resolvers.resolve(result); |
155 | | - } else { |
156 | | - resolvers.reject(new Error('Unsupported command')); |
| 118 | + |
| 119 | + try { |
| 120 | + const nativeResMsg = parseCubestoreResultMessage(msg); |
| 121 | + resolvers.resolve(nativeResMsg); |
| 122 | + } catch (e) { |
| 123 | + resolvers.reject(e); |
157 | 124 | } |
158 | 125 | }); |
159 | 126 | }); |
|
0 commit comments