Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions packages/query-tools/src/data-transforms/record-to-string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Node, Path, Point, Relationship } from 'neo4j-driver';
import type { Node, Path, Relationship } from 'neo4j-driver';
import { isInt, isNode, isPath, isPoint, isRelationship } from 'neo4j-driver';

import type {
Expand All @@ -12,11 +12,6 @@ import {
} from '../types/cypher-data-types';
import { formatFloat } from './format-float';

const spacialFormat = (p: Point): string => {
const zString = p.z !== undefined ? `, z:${p.z}` : '';
return `point({srid:${p.srid.toString()}, x:${p.x}, y:${p.y}${zString}})`;
};

export function propertyToString(
property: CypherProperty,
quoteStrings = true,
Expand All @@ -29,13 +24,13 @@ export function propertyToString(
if (property === null) {
return 'null';
}
if (typeof property === 'boolean') {
return property.toString();
}
if (isInt(property)) {
return property.toString();
}
if (typeof property === 'bigint') {
if (
typeof property === 'boolean' ||
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this look compared to a sequence of if statements. In general the logic would be altered a bit with moving the order of the checks, but the re-ordered conditions are anyway mutually exclusive (never true on both type=string AND type=point), so in this case we are safe

isInt(property) ||
typeof property === 'bigint' ||
isCypherTemporalType(property) ||
isPoint(property)
) {
return property.toString();
}
if (typeof property === 'number') {
Expand All @@ -53,14 +48,6 @@ export function propertyToString(
return 'ByteArray';
}

if (isCypherTemporalType(property)) {
return property.toString();
}

if (isPoint(property)) {
return spacialFormat(property);
}

// This case shouldn't be used, but added as a fallback
return String(property);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/vscode-extension/src/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isInt,
isLocalDateTime,
isLocalTime,
isPoint,
isTime,
} from 'neo4j-driver';
import { isDate } from 'util/types';
Expand Down Expand Up @@ -43,7 +44,8 @@ function valueToNativeType(value: unknown) {
isTime(value) ||
isLocalDateTime(value) ||
isLocalTime(value) ||
isDuration(value)
isDuration(value) ||
isPoint(value)
) {
value = value.toString();
} else if (
Expand Down