MCPcopy Create free account
hub / github.com/bytebase/bytebase / compareQueryRowValues

Function compareQueryRowValues

frontend/src/utils/v1/sql.ts:385–426  ·  view source on GitHub ↗
(
  type: string,
  a: RowValue,
  b: RowValue
)

Source from the content-addressed store, hash-verified

383};
384
385export const compareQueryRowValues = (
386 type: string,
387 a: RowValue,
388 b: RowValue
389): number => {
390 const valueA = extractSQLRowValuePlain(a);
391 const valueB = extractSQLRowValuePlain(b);
392
393 // NULL or undefined values go behind
394 if (isNullOrUndefined(valueA)) return 1;
395 if (isNullOrUndefined(valueB)) return -1;
396
397 // Check if the values are bigints and compare them.
398 const rawA = extractSQLRowValueRaw(a);
399 const rawB = extractSQLRowValueRaw(b);
400 if (typeof rawA === "bigint" && typeof rawB === "bigint") {
401 return rawA < rawB ? -1 : rawA > rawB ? 1 : 0;
402 }
403
404 if (typeof valueA === "number" && typeof valueB === "number") {
405 return valueA - valueB;
406 }
407
408 if (type === "INT" || type === "INTEGER") {
409 const intA = toInt(valueA);
410 const intB = toInt(valueB);
411 return intA - intB;
412 }
413 if (type === "FLOAT") {
414 const floatA = toFloat(valueA);
415 const floatB = toFloat(valueB);
416 return floatA - floatB;
417 }
418 if (type === "DATE" || type === "DATETIME") {
419 const dateA = dayjs(valueA);
420 const dateB = dayjs(valueB);
421 return dateA.isBefore(dateB) ? -1 : dateA.isAfter(dateB) ? 1 : 0;
422 }
423 const stringA = String(valueA);
424 const stringB = String(valueB);
425 return stringA < stringB ? -1 : stringA > stringB ? 1 : 0;
426};
427
428// extractSQLRowValueRaw extracts a raw value from a RowValue.
429const extractSQLRowValueRaw = (value: RowValue | undefined) => {

Callers 1

SingleResultViewFunction · 0.90

Calls 5

isNullOrUndefinedFunction · 0.90
extractSQLRowValuePlainFunction · 0.85
extractSQLRowValueRawFunction · 0.85
toIntFunction · 0.85
toFloatFunction · 0.85

Tested by

no test coverage detected