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

Function normalizePartitionBound

packages/sql/src/schema/partitioning.ts:292–314  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

290
291/** @internal */
292export function normalizePartitionBound(value: string): string {
293 const normalized = normalizeWhitespace(value);
294
295 if (!normalized) {
296 return '';
297 }
298
299 if (/^default$/i.test(normalized)) {
300 return 'default';
301 }
302
303 // Prepend `for values` if the caller passed a bare `with/in/from … to …` clause, then lowercase
304 // PG bound keywords outside quoted literals (so `FROM (MINVALUE) TO ('hello TO world')` becomes
305 // `from (minvalue) to ('hello TO world')` with the inner TO inside the literal preserved).
306 // PG's `pg_get_expr` emits `MINVALUE`/`MAXVALUE`/`NULL` in uppercase, so case-folding them here
307 // prevents a perpetual diff against user-supplied lowercase bounds.
308 const prefixed = /^for values\b/i.test(normalized) ? normalized : `for values ${normalized}`;
309 const lowered = mapOutsideLiterals(prefixed, segment =>
310 segment.replace(PARTITION_BOUND_KEYWORDS, match => match.toLowerCase()),
311 );
312
313 return normalizePartitionSqlFragment(lowered);
314}
315
316const createPartitionBound = (value: string): string => normalizePartitionBound(value);
317

Callers 6

getPartitionsMethod · 0.85
createPartitionBoundFunction · 0.85
createHashPartitionsFunction · 0.85
serializePartitionFunction · 0.85
toEntityPartitionByFunction · 0.85

Calls 4

normalizeWhitespaceFunction · 0.85
mapOutsideLiteralsFunction · 0.85
testMethod · 0.65

Tested by

no test coverage detected