EN

@core / db

1.0.0 ▾
verifiedMIT
GitHub

Postgres with Drizzle: shared client, per-module schemas, transactions and ULID ids

Code8 filesContext~547 tokensscan passed

The exact tree that will be injected, after .genpmignore. Pinned to

src/lib/db/columns.tsread-only · 28d4b9f
// Columnas estándar para que todas las tablas de todos los módulos se parezcan.
import { text, timestamp } from 'drizzle-orm/pg-core';
import { newId } from './ulid.js';

/** Clave primaria `text` con ULID prefijado generado en la app: `id: primaryId('usr')`. */
export const primaryId = (prefix: string) =>
  text('id')
    .primaryKey()
    .$defaultFn(() => newId(prefix));

/** `created_at` / `updated_at` con zona horaria; `updated_at` se actualiza solo en cada `update()`. */
export const timestamps = {
  createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull().defaultNow(),
  updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' })
    .notNull()
    .defaultNow()
    .$onUpdateFn(() => new Date()),
};

Report @core/db

Sign in with GitHub to report a package.