What is entites?

what does the entites parameter in the main.wasp file mean?
3 Replies
kapa.ai
kapa.ai7d ago
Hi @ArDev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Entities in Wasp are one of the most important concepts and define what gets stored in the database. They are the foundation of your app's data model. In short, an Entity defines a model in your database. Wasp uses Prisma ORM to implement all database functionality and occasionally enhances it with a thin abstraction layer. Wasp Entities directly correspond to Prisma's data model. The only requirement for defining Wasp Entities is familiarity with the Prisma Schema Language (PSL), a simple definition language explicitly created for defining models in Prisma[^1^]. In the main.wasp file, the entities parameter is used to specify which entities you wish to use inside your API, Action, or Query[^2^][^3^][^4^][^5^]. For example, if you have a Task entity and you want to use it in your API, you would add it to the api declaration in Wasp like this[^5^]:
api fooBar {
fn: import { fooBar } from "@src/apis",
entities: [Task],
httpRoute: (GET, "/foo/bar")
}
api fooBar {
fn: import { fooBar } from "@src/apis",
entities: [Task],
httpRoute: (GET, "/foo/bar")
}
Wasp will then inject the specified Entity into the API's context argument, giving you access to the Entity's Prisma API[^5^]. ^1^]: [Wasp Docs - Entities (https://wasp-lang.dev/docs/data-model/entities) ^2^]: [Wasp Docs - Using Entities in APIs (https://wasp-lang.dev/docs/advanced/apis#using-entities-in-apis) ^3^]: [Wasp Docs - Using Entities in Actions (https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions) ^4^]: [Wasp Docs - Using Entities in Queries (https://wasp-lang.dev/docs/data-model/operations/queries#using-entities-in-queries) ^5^]: [Wasp Docs - API Reference (https://wasp-lang.dev/docs/advanced/apis#api-reference) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArDev
ArDev7d ago
@kapa.ai in the action thing
kapa.ai
kapa.ai7d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- In Wasp, the entities parameter in an action declaration is used to specify which entities you wish to use inside your action[^1^][^2^][^3^]. For example, if you have a Task entity and you want to use it in your action, you would add it to the action declaration in Wasp like this[^1^]:
action createTask {
fn: import { createTask } from "@src/actions.js",
entities: [Task]
}
action createTask {
fn: import { createTask } from "@src/actions.js",
entities: [Task]
}
Wasp will then inject the specified Entity into the Action's context argument, giving you access to the Entity's Prisma API[^2^]. This allows you to perform operations on the entity within the action, such as creating, updating, or deleting records. ^1^]: [Wasp Docs - Declaring Actions in Wasp (https://wasp-lang.dev/docs/data-model/operations/actions#declaring-actions-in-wasp) ^2^]: [Wasp Docs - Using Entities in Actions (https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions) ^3^]: [Wasp Docs - Creating a New Action (https://wasp-lang.dev/docs/tutorial/actions#creating-a-new-action) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server