wasp/web/versioned_docs/version-0.11.8/tutorial/04-entities.md
Martin Šošić 7f91081bd8
Fix broken documentation links & remove old docs.
* Removed old docs leftovers.

* Fixed broken links in the docs.

* fix
2024-01-12 17:42:53 +01:00

1.6 KiB

title
4. Database Entities

import useBaseUrl from '@docusaurus/useBaseUrl';

Entities are one of the most important concepts in Wasp and are how you define what gets stored in the database.

Since our Todo app is all about tasks, we will define a Task entity in the Wasp file:

// ...

entity Task {=psl
    id          Int     @id @default(autoincrement())
    description String
    isDone      Boolean @default(false)
psl=}

:::note Wasp uses Prisma as a way to talk to the database. You define entities by defining Prisma models using the Prisma Schema Language (PSL) between the {=psl psl=} tags.

Read more in the Entities section of the docs. :::

To update the database schema to include this entity, stop the wasp start process, if its running, and run:

wasp db migrate-dev

You'll need to do this any time you change an entity's definition. It instructs Prisma to create a new database migration and apply it to the database.

To take a look at the database and the new Task entity, run:

wasp db studio

This will open a new page in your browser to view and edit the data in your database.

<img alt="Todo App - Db studio showing Task schema" src={useBaseUrl('img/todo-app-db-studio-task-entity.png')} style={{ border: "1px solid black" }} />

Click on the Task entity and check out its fields! We don't have any data in our database yet, but we are about to change that.