A query function is used to read data from the database. You define it using the query function from your generated server module. You must provide an args object containing validators (using v from convex/values) to define the schema of the arguments, and a handler function that receives ctx (the context) and args.
// functions.js
import { query } from "./_generated/server";
import { v } from "convex/values";
export const myQueryFunction = query({
// Validators for arguments.
args: {
first: v.number(),
second: v.string(),
},
// Function implementation.
handler: async (ctx, args) => {
// Read the database as many times as you need here.
const documents = await ctx.db.query("tablename").collect();
// Arguments passed from the client are properties of the args object.
console.log(args.first, args.second);
return documents;
},
});