Drizzle Express Guide
This guide covers the usage details of Drizzle Express.
Scaffold
A scaffold, in Drizzle Express, is all of the starter code, including the routes, controller, service, and schema, that is required to have a fully functional CRUD API.
After the initial configuration is completed from running the init command, you can create REST API scaffolding with the scaffold command.
The -c option takes a space-separated string of column configurations in the following format: column_name:dataType. The data types map directly to most of the available data types in Drizzle ORM. See Data Types for a list of supported data types.
The id, created_at, and updated_at fields are automatically generated by Drizzle Express, and should be omitted from the command.
After scaffolding, you can review the schema and make any necessary changes before running the database migrations.
Example:
npx drizzle-express@latest scaffold products -c title:text price:integer description:textData Types
See Data Types.
Primary key strategy
See Primary key strategy.
Foreign key constraints
Drizzle Express supports adding foreign key constraints using the following special references data type.
For example, a one to many relationship where a post belongs to a category can be set up using the following scaffolds.
First, scaffold the one side of the relationship.
npx drizzle-express@latest scaffold category -c title:textSecond, scaffold the many side of the relationship:
npx drizzle-next@latest scaffold post -c category_id:references title:textProject structure
Drizzle Express uses the following project structure:
- drizzle
- scripts
- src
- controllers
- db
- lib
- middlewares
- routes
- services