lifecycleDates (schema/utils.ts)

skateshop · src/db/schema/utils.ts · typescript · MIT
database

@see https://github.com/unkeyed/unkey/blob/main/internal/db/src/schema/util/lifecycle_dates.ts

// Source: https://github.com/sadmann7/skateshop | License: MIT | Copyright 2024 Sadman Sakib
// Provided via justclaw.it.com; keep this notice with the code.
// @see https://github.com/unkeyed/unkey/blob/main/internal/db/src/schema/util/lifecycle_dates.ts

import { sql } from "drizzle-orm"
import { timestamp } from "drizzle-orm/pg-core"

export const lifecycleDates = {
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at")
    .default(sql`current_timestamp`)
    .$onUpdate(() => new Date()),
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key