MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / resolvePartitionExpression

Function resolvePartitionExpression

packages/sql/src/schema/partitioning.ts:244–265  ·  view source on GitHub ↗
(
  meta: EntityMetadata,
  expression: NonNullable<EntityPartitionBy['expression']>,
  quoteIdentifier: (id: string) => string,
)

Source from the content-addressed store, hash-verified

242 * user owns identifier quoting inside a raw expression.
243 */
244const resolvePartitionExpression = (
245 meta: EntityMetadata,
246 expression: NonNullable<EntityPartitionBy['expression']>,
247 quoteIdentifier: (id: string) => string,
248): string => {
249 if (typeof expression === 'function') {
250 return normalizeWhitespace(expression(meta.createSchemaColumnMappingObject()));
251 }
252
253 if (Array.isArray(expression)) {
254 return (expression as readonly string[]).map(key => resolvePartitionKey(meta, key, quoteIdentifier)).join(', ');
255 }
256
257 const trimmed = (expression as string).trim();
258 const keys = splitCommaSeparatedIdentifiers(trimmed);
259
260 if (keys) {
261 return keys.map(key => resolvePartitionKey(meta, key, quoteIdentifier)).join(', ');
262 }
263
264 return trimmed;
265};
266
267const createPartitionDefinition = (type: EntityPartitionBy['type'], expression: string): string =>
268 `${type.toLowerCase()} (${normalizeWhitespace(expression)})`;

Callers 1

getTablePartitioningFunction · 0.85

Calls 6

normalizeWhitespaceFunction · 0.85
resolvePartitionKeyFunction · 0.85
joinMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected