Files
drizzlebox/README.md
glm-5.1 d0a0de766b feat: fork drizzle-typebox as @alkdev/drizzlebox
- Rebrand package from drizzle-typebox to @alkdev/drizzlebox
- Replace @sinclair/typebox with @alkdev/typebox in all source and test files
- Replace @sinclair/typebox with @alkdev/typebox in rollup externals
- Convert tsconfig.json from monorepo extends to standalone config
- Fix build script monorepo remnant (dist.new -> dist)
- Add missing devDependencies (recast, tsx, typescript, resolve-tspaths)
- Replace monorepo link dependency for drizzle-orm with ^0.38.4
- Add .gitignore, LICENSE (Apache-2.0 with attribution), and README
- Initialize git repo with remote at git.alk.dev:alkdev/drizzlebox
2026-04-25 09:45:14 +00:00

2.2 KiB

@alkdev/drizzlebox

Generate TypeBox schemas from Drizzle ORM schemas.

This is a fork of drizzle-typebox by the Drizzle Team, adapted for use with @alkdev/typebox (a maintained fork of @sinclair/typebox).

Install

npm install @alkdev/drizzlebox
npm install @alkdev/typebox
npm install drizzle-orm

Features

  • Create select schemas for tables, views, and enums
  • Create insert and update schemas for tables
  • Supports all dialects: PostgreSQL, MySQL, and SQLite
  • Custom TypeBox instance support via createSchemaFactory

Usage

import { pgEnum, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
import { createInsertSchema, createSelectSchema, createUpdateSchema } from '@alkdev/drizzlebox';
import { Type } from '@alkdev/typebox';
import { Value } from '@alkdev/typebox/value';

const users = pgTable('users', {
	id: serial('id').primaryKey(),
	name: text('name').notNull(),
	email: text('email').notNull(),
	role: text('role', { enum: ['admin', 'user'] }).notNull(),
	createdAt: timestamp('created_at').notNull().defaultNow(),
});

// Schema for inserting a user
const insertUserSchema = createInsertSchema(users);

// Schema for updating a user
const updateUserSchema = createUpdateSchema(users);

// Schema for selecting a user
const selectUserSchema = createSelectSchema(users);

// Overriding fields
const insertUserSchema = createInsertSchema(users, {
	role: Type.String(),
});

// Refining fields
const insertUserSchema = createInsertSchema(users, {
	id: (schema) => Type.Number({ ...schema, minimum: 0 }),
	role: Type.String(),
});

// Validation
const isUserValid: boolean = Value.Check(insertUserSchema, {
	name: 'John Doe',
	email: 'johndoe@test.com',
	role: 'admin',
});

Differences from drizzle-typebox

  • Uses @alkdev/typebox instead of @sinclair/typebox
  • Standalone package (no monorepo dependency)
  • Published as @alkdev/drizzlebox on npm

Attribution

Based on drizzle-typebox by the Drizzle Team, licensed under Apache-2.0.