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

Function resolvePartitionKey

packages/sql/src/schema/partitioning.ts:211–235  ·  view source on GitHub ↗
(meta: EntityMetadata, key: string, quoteIdentifier: (id: string) => string)

Source from the content-addressed store, hash-verified

209};
210
211const resolvePartitionKey = (meta: EntityMetadata, key: string, quoteIdentifier: (id: string) => string): string => {
212 const trimmed = key.trim().replaceAll('"', '');
213
214 if (!trimmed) {
215 throw new Error(`Entity ${meta.className} has invalid partitionBy option: empty partition key`);
216 }
217
218 const prop =
219 meta.root.properties[trimmed as keyof typeof meta.root.properties] ??
220 Object.values(meta.root.properties).find(
221 candidate => candidate.fieldNames?.length === 1 && candidate.fieldNames[0] === trimmed,
222 );
223
224 if (!prop) {
225 throw new Error(`Entity ${meta.className} has invalid partitionBy option: unknown partition key '${key.trim()}'`);
226 }
227
228 if (prop.fieldNames?.length !== 1) {
229 throw new Error(
230 `Entity ${meta.className} has invalid partitionBy option: partition key '${key.trim()}' maps to multiple columns ('${prop.fieldNames?.join("', '")}'); list them explicitly as partition keys`,
231 );
232 }
233
234 return quoteIdentifier(prop.fieldNames[0]);
235};
236
237/**
238 * Resolve the partition expression to a SQL fragment. Column-reference forms (array of keys

Callers 1

Calls 4

quoteIdentifierFunction · 0.85
findMethod · 0.65
joinMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected