Skip to content

Commit

Permalink
Fix encoding of range types
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jan 24, 2022
1 parent 8c6afe3 commit b9a0959
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions packages/dataplan-pg/src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,41 @@ export function rangeOfCodec<
fromPg(value) {
const parsed = rangeParse(value);
return {
lower: parsed.lower,
lowerInclusive: parsed.isLowerBoundClosed(),
upper: parsed.upper,
upperInclusive: parsed.isUpperBoundClosed(),
start:
parsed.lower != null
? {
value: parsed.lower,
inclusive: parsed.isLowerBoundClosed(),
}
: null,
end:
parsed.upper != null
? {
value: parsed.upper,
inclusive: parsed.isUpperBoundClosed(),
}
: null,
};
},
toPg(value) {
if (value.lower == null && value.upper == null) {
return "";
let str = "";
if (value.start == null) {
str += "(";
} else {
str += `${value.start.inclusive ? "[" : "("}${escapeRangeValue(
value.start.value,
innerCodec,
)}`;
}
return `${value.lowerInclusive ? "[" : "("}${escapeRangeValue(
value.lower,
innerCodec,
)},${escapeRangeValue(value.upper, innerCodec)}${
value.upperInclusive ? "]" : ")"
}`;
str += ",";
if (value.end == null) {
str += ")";
} else {
str += `${escapeRangeValue(value.end.value, innerCodec)}${
value.end.inclusive ? "]" : ")"
}`;
}
return str;
},
columns: undefined,
};
Expand Down

0 comments on commit b9a0959

Please sign in to comment.