Range types support #2438
dankochetov
started this conversation in
Ideas
Replies: 4 comments
-
Here's an implementation using import { Range, RANGE_LB_INC, parse as rangeParse, serialize as rangeSerialize, } from 'postgres-range'
interface TimeRangeInput {
endMs: number
startMs: number
}
export class Int4Range {
constructor(public readonly range: Range<number>) {}
get start(): RangeBound<number> | null {
return this.range.lower != null
? {
value: this.range.lower,
inclusive: this.range.isLowerBoundClosed(),
}
: null
}
get end(): RangeBound<number> | null {
return this.range.upper != null
? {
value: this.range.upper,
inclusive: this.range.isUpperBoundClosed(),
}
: null
}
static fromInput(input: TimeRangeInput): Int4Range {
const range = new Range<number>(
input.startMs,
input.endMs,
RANGE_LB_INC,
)
return new Int4Range(range)
}
}
const int4range = customType<{
data: Int4Range
}>({
dataType: () => 'int4range',
fromDriver: (value: unknown): Int4Range => {
if (typeof value !== 'string') {
throw new Error('Expected string')
}
const parsed = rangeParse(value, (val) => parseInt(val, 10))
return new Int4Range(parsed)
},
toDriver: (value: Int4Range): string => rangeSerialize(value.range),
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
is this still being worked on? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would love to see support for this, specifically |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would like to see this too. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://www.postgresql.org/docs/current/rangetypes.html
Beta Was this translation helpful? Give feedback.
All reactions