Processing List to add in DB
Thank you very much for your work on WASP and for the great documentation.
I am having an issue, I am sending from the frontend 3 inputs at the same time to the backend. And from the action function I processed these 3 inputs and I created a list then I tried to loop through this list add to the database each item of this list using context.entities.ENTITY.create but it doesn't work. It seems that an action function can only process 1 entity to add to the database.
I also tried to use createMany with context entities but I have a TypeError in the console : `
Hope it makes sense.
Please let me know if want me to share some code.
8 Replies
Hey @imartinat glad to hear you find the docs helpful! π Action can deal with multiple entities, but you have to specify them in
entities
property in your .wasp file.
Can you share your action code with us (wasp declaration and js/ts code)? Thanks!Thanks for your quick answer, in my wasp file I have :
I should rename to createPrompList
In actions.js, I have :
Wohooo @imartinat, you just became a Waspeteer level 1!
Since
create
is an async operation, you need to await each of them.
For example like this:
Thank you very much. It now works.
Would it be possible to use createMany from Prisma? I tried to use it with context entities but I have a TypeError in the console :
Prisma doesn't support
createMany
unfortunately when using SQLite database π’
https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#remarks-10
Your options are to move to PostgrSQL by adding
and providing a DATABASE_URL env variable in the .env.server
https://wasp-lang.dev/docs/language/features#postgresql
... or continue using create
in a loop as you are using it now.Thank you very much for your explanation. I am just testing now with SQLite so I will keep using loops. But it's good to know if I switch to PostgreSQL . Thanks again for your help!
no problem! btw what are you building? would love to see it in action π
ah I see now you mentioned it in general, very cool π