Skip to content

Intervals

A Postgres Interval Type is handled by no-orm by using the postgres-interval npm package.

CREATE TABLE ... (
-- ...
a_interval INTERVAL NOT NULL,
-- ...
);

You can create an interval to be added as a column using postgres-interval:

import { default as parseInterval } from "postgres-interval";
const interval = parseInterval("1 year 2 mons 3 days 04:05:06");

Then a row being read with an interval column has access to the IPostgresInterval interface:

import type { IPostgresInterval } from "postgres-interval";
const interval: IPostgresInterval = row.a_interval; // { days: number; hours: number ... }