missing delete mutation example in the docs
Hey guys, I've been checking out convex. I managed to do auth, get and post operations.
But I can't seem to find docs on how to delete an item from a table. I've attached the type error I'm getting. I'm also attaching the post mutation which works fine.
If there're docs for this, please point me to them, thanks!
13 Replies
hey @rutenisraila ! thanks for trying convex
ids are database-unique. every id is the only id with that value in the whole database, not just for the table
in fact, ids embed information in them that lets convex know which table the id came from
so, the
delete
method doesn't need the table name. only the id. https://docs.convex.dev/api/interfaces/server.DatabaseWriter#deleteInterface: DatabaseWriter | Convex Developer Hub
server.DatabaseWriter
if you remove the 'decisions' argument from that method, everything should work
hi Jamie, thanks for the fast response, that's what I initially tried, but I get this type error:
am I missing something?
id isn't a v.string(), it's a
v.id('table-name')
. see example here: https://github.com/get-convex/convex-demos/blob/c0d84a85e533ed6fdf8a83f9469d88709335bbb0/relational-data-modeling/README.md?plain=1#L23GitHub
convex-demos/relational-data-modeling/README.md at c0d84a85e533ed6f...
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
in your case I suppose it's a
v.id('decisions')
this just gives you even more type safety that you're actually passing an id from the proper table into your convex functionsyooo, it works! Thanks for help Jamie. Keep up the great work!
glad to hear it!
The docs for delete are here, including validator example:
https://docs.convex.dev/database/writing-data#deleting-documents
Let us know if you had trouble finding this with the docs search.
Writing Data | Convex Developer Hub
Mutations can insert, update, and
hi @Michal Srb thanks for the docs link!
one thing that took me a bit of time to get used to is that in convex folder I have to reference type with "v", and in the app code I have to import them _generated/dataModel.
I think I saw it somewhere else in the docs, but not in the delete. Anyways, still a really cool product I love the analytics dashboard. This makes feel cloud function development achievable for mortals, I've been having a lot of fun 😄
is there a way for us to know this too? Having an id and knowing which table it comes from
@stefano we don’t expose this atm, no, leaving the option to make ids not include their tables index for the future.
You should be able to work around this by storing and processing a table name along with your id.