mikro-orm-temporal
v2.0.3
Published
Temporal types for Mikro ORM
Downloads
786
Maintainers
Readme
Temporal for Mikro ORM
This package provides Mikro ORM types for common Temporal objects.
The library exports the following types:
DurationTypePlainDateTypePlainDateTimeTypePlainTimeTypeOffsetDateTimeTypeInstantTypePlainMonthDayTypePlainYearMonthType
Installation
Install via your favorite package manager:
npm install mikro-orm-temporal
# or
pnpm add mikro-orm-temporal
# or
yarn add mikro-orm-temporalUsage
With defineEntity (recommended)
Use p.type() from @mikro-orm/core to wire up any temporal type, then chain modifiers like
.nullable() as needed:
import { defineEntity, p } from '@mikro-orm/core';
import { OffsetDateTimeType, PlainDateType } from 'mikro-orm-temporal';
const EventSchema = defineEntity({
name: 'Event',
properties: {
id: p.integer().primary(),
startsAt: p.type(OffsetDateTimeType),
endsAt: () => p.type(OffsetDateTimeType).nullable(),
date: p.type(PlainDateType),
},
});
export class Event extends EventSchema.class {}
EventSchema.setClass(Event);Caveats
- Durations are stored as
INTERVALin Postgres and asVARCHAR(ISO string) on all other platforms.
