Add MySQL support for SQL replacer function

pull/1323/head
Chris Walsh 2022-07-22 00:09:29 -07:00
parent 8d5c9c9711
commit 7f853c87f0
No known key found for this signature in database
GPG Key ID: 28EE0CCA6032019E
1 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { parseFilters, rawQuery } from 'lib/queries'; import { getDatabase, parseFilters, rawQuery } from 'lib/queries';
import { MYSQL, POSTGRESQL } from 'lib/constants';
export function getPageviewParams( export function getPageviewParams(
param, param,
@ -17,10 +18,16 @@ export function getPageviewParams(
params, params,
); );
let splitFn;
let db = getDatabase();
if (db === MYSQL) splitFn = 'substring_index';
if (db === POSTGRESQL) splitFn = 'split_part';
if (!splitFn) return Promise.reject(new Error('Unknown database.'));
return rawQuery( return rawQuery(
`select * from ( `select * from (
select select
url, split_part(split_part(url, concat($1, '='), 2), '&', 1) param url, ${splitFn}(${splitFn}(url, concat($1, '='), 2), '&', 1) param
from from
pageview pageview
${joinSession} ${joinSession}