Skip to content

monolayer / schema / date

Function: date()

date(): PgDate

Column that stores dates (without time of day).

Returns

PgDate

Remarks

Range: 4713 BC and 5874897 AD.

The JavaScript Date implementation can represent only a maximum of September 13, 275760 AD. If you need to read/store dates after this maximum, you'll have to implement a custom type serializer and parser with node-pg-types.

Kysely database schema type definition

ts
{
  readonly __select__: Date | null;
  readonly __insert__: Date | string | null | undefined;
  readonly __update__: Date | string | null;
};

Nullability and optionality will change according to the column's constraints, generated values, and default data values.

Zod Schema

Types:

ts
{
  input?: Date | string | null | undefined;
  output?: Date | null | undefined;
}

Nullability and optionality will change according to the column's constraints, generated values, and default data values.

Validations: *

  • Value must be Date, string, or null.
  • Explicit undefined values are rejected.
  • String values must be coercible to Date.

Example

ts
import { date, schema, table } from "monolayer/pg";
import { zodSchema } from "monolayer/zod";

const dbSchema = schema({
  tables: {
    example: table({
      columns: {
        createdAt: date(),
      },
    }),
  },
});

// Kysely database schema type
type DB = typeof dbSchema.infer;
// Zod Schema
const schema = zodSchema(database.tables.example);

See

PostgreSQL Doc: date