15 lines
431 B
JavaScript
15 lines
431 B
JavaScript
import { sqlField, sqlIdent, sqlStringLiteral } from "./sql-safe";
|
|
export default function sqlGenGrabConcatStr({ alias, field, separator = ",", distinct, }) {
|
|
let gc = `GROUP_CONCAT(`;
|
|
if (distinct) {
|
|
gc += `DISTINCT `;
|
|
}
|
|
gc += sqlField(field);
|
|
if (!distinct) {
|
|
gc += `, ${sqlStringLiteral(String(separator))}`;
|
|
}
|
|
gc += `)`;
|
|
gc += ` AS ${sqlIdent(alias, "alias")}`;
|
|
return gc;
|
|
}
|