Skip to content

Commit 05984a2

Browse files
committed
refactor(schema-compiler): Move _normaliseResponse to static method
1 parent 9f49f97 commit 05984a2

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

packages/cubejs-schema-compiler/test/integration/clickhouse/ClickHouseDbRunner.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class ClickHouseDbRunner extends BaseDbRunner {
166166

167167
const results = await Promise.all(requests);
168168

169-
return results.map(_normaliseResponse);
169+
return results.map(ClickHouseDbRunner._normaliseResponse);
170170
}
171171

172172
public async testQuery(queryAndParams: [string, Array<unknown>], prepareDataSet?: ((client: ClickHouseClient) => Promise<void>) | null): Promise<Array<Record<string, unknown>>> {
@@ -181,34 +181,34 @@ export class ClickHouseDbRunner extends BaseDbRunner {
181181
protected override newTestQuery(compilers: unknown, query: unknown): ClickHouseQuery {
182182
return new ClickHouseQuery(compilers, query);
183183
}
184-
}
185184

186-
//
187-
//
188-
// ClickHouse returns DateTime as strings in format "YYYY-DD-MM HH:MM:SS"
189-
// cube.js expects them in format "YYYY-DD-MMTHH:MM:SS.000", so translate them based on the metadata returned
190-
//
191-
// https://github.com/statsbotco/cube.js/pull/98#discussion_r279698399
192-
//
193-
function _normaliseResponse(res: any): Array<Record<string, unknown>> {
194-
if (process.env.DEBUG_LOG === 'true') console.log(res);
195-
if (res.data) {
196-
res.data.forEach(row => {
197-
for (const field in row) {
198-
const value = row[field];
199-
if (value !== null) {
200-
const meta = res.meta.find(m => m.name == field);
201-
if (meta.type.includes('DateTime')) {
202-
row[field] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
203-
} else if (meta.type.includes('Date')) {
204-
row[field] = `${value}T00:00:00.000`;
205-
} else if (meta.type.includes('Int') || meta.type.includes('Float')) {
206-
// convert all numbers into strings
207-
row[field] = `${value}`;
185+
//
186+
//
187+
// ClickHouse returns DateTime as strings in format "YYYY-DD-MM HH:MM:SS"
188+
// cube.js expects them in format "YYYY-DD-MMTHH:MM:SS.000", so translate them based on the metadata returned
189+
//
190+
// https://github.com/statsbotco/cube.js/pull/98#discussion_r279698399
191+
//
192+
protected static _normaliseResponse(res: any): Array<Record<string, unknown>> {
193+
if (process.env.DEBUG_LOG === 'true') console.log(res);
194+
if (res.data) {
195+
res.data.forEach(row => {
196+
for (const field in row) {
197+
const value = row[field];
198+
if (value !== null) {
199+
const meta = res.meta.find(m => m.name == field);
200+
if (meta.type.includes('DateTime')) {
201+
row[field] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
202+
} else if (meta.type.includes('Date')) {
203+
row[field] = `${value}T00:00:00.000`;
204+
} else if (meta.type.includes('Int') || meta.type.includes('Float')) {
205+
// convert all numbers into strings
206+
row[field] = `${value}`;
207+
}
208208
}
209209
}
210-
}
211-
});
210+
});
211+
}
212+
return res.data;
212213
}
213-
return res.data;
214214
}

0 commit comments

Comments
 (0)