Remote / foldkit-remote-drizzle

entityChecks

function · packages/remote-drizzle/src/checks.ts:575

function entityChecks<E extends Domain.AnyEntity>(
  entity: E,
  columns: Readonly<Record<string, PgColumn>>,
  options?: EntityCheckOptions<E>,
): Array<PgCheckBuilder>
function entityChecks<E extends Domain.AnyEntity>(
  entity: E,
  columns: Readonly<Record<string, SQLiteColumn>>,
  options?: EntityCheckOptions<E>,
): Array<SQLiteCheckBuilder>

The CHECKs an Entity implies, as Drizzle check()s for its table's own definition, so drizzle-kit writes them into the migration that makes it:

ts
const posts = sqliteTable(
  'posts',
  { id: text('id').primaryKey(), body: text('body').notNull() },
  t => entityChecks(Post, t),
)

It takes the Entity, not a binding: Drizzle reads the callback lazily, and the binding is made from the table. bind refuses a table whose checks disagree.