JeffWScottJ
Convex Community6mo ago
3 replies
JeffWScott

Getting 1 item by _ID from the DB.

This code seems to work compile and not throw any errors.
import { v } from "convex/values";
import { query } from "./_generated/server";

export const get = query({
    args: {},
    handler: async (ctx) => {
        const chats = await ctx.db.query("chats").collect();
        return chats
    },
});

export const getOne = query({
    args: {
        chatId: v.id("chats")
    },
    handler: async (ctx, args) => {
        const chat = await ctx.db.get(args.chatId)
        return chat
    },
});


But I can't use getOne.

This code:
    import { useQuery } from 'convex-svelte';
    import { api } from '$convex/_generated/api.js';

    const query = useQuery(api.chats.getOne, {chatId: "jh7dtfhvyqp0qmmn7q4y3zhh6n7m8tcn"});****


tells me "Type 'string' is not assignable to type 'Id<"chats">'. Type 'string' is not assignable to type '{ __tableName: "chats"; }'"


I just want to get a specific chat via that _id that is in the database... What am I doing wrong becvause all of the examples say this should work.

getting all the chats works fine.

please help!
Was this page helpful?