UNPKG

mysql-all-in-one

Version:

A package that allows you to have a complete interaction with a MYSQL database, allowing to connect to the database, retrieve data and create queries.

29 lines (28 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.group = void 0; const utils_1 = require("../../utils"); const groupBy = (value, alias) => { if (Array.isArray(value) && value !== null && value !== undefined) return value .map((v) => groupBy(v, alias)) .filter((v) => !!v) .join(','); if (typeof value === 'string') return (0, utils_1.safeApplyAlias)((0, utils_1.escapeNames)(value), alias); if (typeof value === 'object' && value.__no_alias) { return groupBy(value.__no_alias); } if (typeof value === 'object' && value.__expression) { if (typeof value.__expression === 'string') return value.__expression; if (Array.isArray(value.__expression)) return value.__expression.join(','); } return undefined; }; const group = (value, defaultAlias) => { const groupResult = groupBy(value, defaultAlias); return groupResult ? ` GROUP BY ${groupResult}` : ''; }; exports.group = group;