Skip to main content

generating

The psy cli provides three commands for generating Dream models and their accompanying migrations and serializers:

yarn psy g:model  --help
yarn psy g:sti-child --help
yarn psy g:resource --help

The resource generator is used when a model will be displayed and/or manipulated via an API endpoint. The model generator is used to generate a model without an API endpoint. And, as the name indicates, the STI child generator is used to generate STI children.

Resource generator commands can be found in the resource generator documentation, and the sti-child has its own, dedicated documentation, but here are some examples of the model and sti-child generator:

yarn psy g:model --no-serializer User email:citext first_name:citext last_name:citext

yarn psy g:model Guest User:belongs_to

yarn psy g:model --sti-base-serializer Room \
type:enum:room_types:Bathroom,Bedroom,Kitchen,Den,LivingRoom \
Place:belongs_to position:integer:optional deleted_at:datetime:optional

# use the --help flag to inspect all of the options

snake_casing column, table, and enum names

Since sql is a case-insensitive language, it is encouraged that you write your columns and tables using snake case. Dream leverages a Kysely setting to automatically convert snake case to camel case so that your Typescript will use the conventional camel case while the database retains the database convention of snake case.