@@ -227,7 +227,33 @@ export class ClickHouseDriver extends BaseDriver implements DriverInterface {
227227 }
228228
229229 protected queryResponse ( query : string , values : unknown [ ] ) {
230- const formattedQuery = sqlstring . format ( query , values ) ;
230+ // const formattedQuery = sqlstring.format(query, values);
231+ const formattedQuery = query ;
232+
233+ // TODO override param
234+
235+ // `queryOptions` object will be merged into query params via querystring.stringify
236+ // https://github.com/cube-js/apla-node-clickhouse/blob/5a6577fc97ba6911171753fc65b2cd2f6170f2f7/src/clickhouse.js#L347-L348
237+ // https://github.com/cube-js/apla-node-clickhouse/blob/5a6577fc97ba6911171753fc65b2cd2f6170f2f7/src/clickhouse.js#L265-L266
238+ // https://github.com/cube-js/apla-node-clickhouse/blob/5a6577fc97ba6911171753fc65b2cd2f6170f2f7/src/clickhouse.js#L336-L338
239+ // https://github.com/cube-js/apla-node-clickhouse/blob/5a6577fc97ba6911171753fc65b2cd2f6170f2f7/src/clickhouse.js#L173-L175
240+
241+ // We can use `toSearchParams` or `formatQueryParams` from `@clickhouse/client-common` to prepare params, and extract only interesting ones
242+ // Beware - these functions marked as "For implementations usage only - should not be re-exported", so, probably, ot could be moved or disappear completely
243+ // https://github.com/ClickHouse/clickhouse-js/blob/a15cce93545c792852e34c05ce31954c75d11486/packages/client-common/src/utils/url.ts#L57-L61
244+
245+ // HTTP interface itself is documented, so it should be fine
246+ // https://clickhouse.com/docs/en/interfaces/cli#cli-queries-with-parameters
247+ // https://clickhouse.com/docs/en/interfaces/http#cli-queries-with-parameters
248+
249+ // TODO prepare values
250+ const paramsValues = Object . fromEntries ( values . map ( ( value , idx ) => {
251+ const paramName = `p${ idx } ` ;
252+ const paramKey = `param_${ paramName } ` ;
253+ // TODO prepare value
254+ const preparedValue = value ;
255+ return [ paramKey , value ] ;
256+ } ) ) ;
231257
232258 return this . withConnection ( ( connection , queryId ) => connection . querying ( formattedQuery , {
233259 dataObjects : true ,
@@ -241,6 +267,9 @@ export class ClickHouseDriver extends BaseDriver implements DriverInterface {
241267 //
242268 //
243269 ...( this . readOnlyMode ? { } : { join_use_nulls : 1 } ) ,
270+
271+ // Add parameter values to query string
272+ ...paramsValues ,
244273 }
245274 } ) ) ;
246275 }
0 commit comments