This commit is contained in:
syuilo 2022-02-06 08:39:23 +09:00
parent cc7a1808ec
commit efe62eb303

View File

@ -365,22 +365,22 @@ export default abstract class Chart<T extends Schema> {
if (v > 0) queryForDay[name] = () => `"${name}" + ${v}`; if (v > 0) queryForDay[name] = () => `"${name}" + ${v}`;
if (v < 0) queryForDay[name] = () => `"${name}" - ${Math.abs(v)}`; if (v < 0) queryForDay[name] = () => `"${name}" - ${Math.abs(v)}`;
} else if (Array.isArray(v) && v.length > 0) { // ユニークインクリメント } else if (Array.isArray(v) && v.length > 0) { // ユニークインクリメント
const name = uniqueTempColumnPrefix + k.replaceAll('.', columnDot); const tempColumnName = uniqueTempColumnPrefix + k.replaceAll('.', columnDot);
// TODO: item が文字列以外の場合も対応
// TODO: item をSQLエスケープ // TODO: item をSQLエスケープ
// TODO: 値が重複しないようにしたい const itemsForHour = v.filter(item => !logHour[tempColumnName].includes(item)).map(item => `"${item}"`);
const items = v.map(item => `"${item}"`).join(','); const itemsForDay = v.filter(item => !logDay[tempColumnName].includes(item)).map(item => `"${item}"`);
queryForHour[name] = () => `array_cat("${name}", '{${items}}'::varchar[])`; if (itemsForHour.length > 0) queryForHour[tempColumnName] = () => `array_cat("${tempColumnName}", '{${itemsForHour.join(',')}}'::varchar[])`;
queryForDay[name] = () => `array_cat("${name}", '{${items}}'::varchar[])`; if (itemsForDay.length > 0) queryForDay[tempColumnName] = () => `array_cat("${tempColumnName}", '{${itemsForDay.join(',')}}'::varchar[])`;
} }
} }
for (const [k, v] of Object.entries(this.schema)) { // bake unique count
const name = columnPrefix + k.replaceAll('.', columnDot); for (const [k, v] of Object.entries(finalDiffs)) {
if (v.uniqueIncrement) { if (this.schema[k].uniqueIncrement) {
const name = columnPrefix + k.replaceAll('.', columnDot);
const tempColumnName = uniqueTempColumnPrefix + k.replaceAll('.', columnDot); const tempColumnName = uniqueTempColumnPrefix + k.replaceAll('.', columnDot);
queryForHour[name] = new Set([...finalDiffs[k], ...logHour[tempColumnName]]).size; queryForHour[name] = new Set([...v, ...logHour[tempColumnName]]).size;
queryForDay[name] = new Set([...finalDiffs[k], ...logDay[tempColumnName]]).size; queryForDay[name] = new Set([...v, ...logDay[tempColumnName]]).size;
} }
} }