get-convex / convex-svelte

https://convex-svelte.vercel.app
Apache License 2.0
23 stars 5 forks source link

More Crud Examples in Documentation #7

Open gerhardcit opened 2 months ago

gerhardcit commented 2 months ago

Could you provide examples on how to use delete, patch etc as well. New to Convex and so far the svelte examples are VERY basic. Its fine to query a db, but what about the CRUD operations? It would really help if you can expand on how that is used.

Convex docs are mostly based around React examples. Which is not helpful.

eg: I have /src/convex/tasks.ts

import { mutation } from "./_generated/server";
import { v } from "convex/values";

export const deleteTask = mutation({
  args: { id: v.id("tasks") },
  // args: { id: v.string() },
  handler: async (ctx, args) => {
    await ctx.db.delete(args.id);
  },
});

then in src/routes/page.svelte

import { useConvexClient } from 'convex-svelte';
const client = useConvexClient();

const deleteTask = async (taskId: string) => {
       await client.mutation(api.tasks.deleteTask, { id: taskId });
};

But then this: How do I send an id?

image
andrewwebbdeveloper commented 1 month ago

Early days for me with TS and Convex - but using a type assertion works. { id: taskId as Id<'tasks'> }

I expect at some point the taskId string has to be cast to that type.

programmingenjoyer219 commented 2 weeks ago

I've built this simple todo-application using Convex and Sveltekit, this project aims to implement CRUD functionality in a modularized way. Here's the link to the GitHub repo of the project: https://github.com/programmingenjoyer219/convex-sveltekit-todo-app

Your suggestions and modifications to the project will be appreciated.