(meta: EntityMetadata, key: string, quoteIdentifier: (id: string) => string)
| 209 | }; |
| 210 | |
| 211 | const 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 |
no test coverage detected