| 265 | // Returns the SELECT expression when querying the groups table directly (no join alias). |
| 266 | // Use for fetching distinct values for group.* properties. |
| 267 | export function getGroupPropertySelect(property: string): string { |
| 268 | const withoutPrefix = property.replace(/^group\./, ''); |
| 269 | if (withoutPrefix === 'name') { |
| 270 | return 'name'; |
| 271 | } |
| 272 | if (withoutPrefix === 'type') { |
| 273 | return 'type'; |
| 274 | } |
| 275 | if (withoutPrefix === 'id') { |
| 276 | return 'id'; |
| 277 | } |
| 278 | if (withoutPrefix.startsWith('properties.')) { |
| 279 | const propKey = withoutPrefix.replace(/^properties\./, ''); |
| 280 | return `properties[${sqlstring.escape(propKey)}]`; |
| 281 | } |
| 282 | return 'id'; |
| 283 | } |
| 284 | |
| 285 | // Returns the SELECT expression when querying the profiles table directly (no join alias). |
| 286 | // Use for fetching distinct values for profile.* properties. |