Hmza
Hmza
CCConvex Community
Created by Hmza on 9/12/2024 in #support-community
convex x hono
i'm not able to make the hono .notfound endpoint work. i get errors if i just visit a wrong path rather it showing a message of not found or something.
import { Hono } from "hono";
import { HonoWithConvex, HttpRouterWithHono } from "convex-helpers/server/hono";
import { ActionCtx } from "./_generated/server";
import { internal } from "./_generated/api";
import { z } from "zod";

const app: HonoWithConvex<ActionCtx> = new Hono();

const mySchema = z.object({
number: z.string().min(1),
cursor: z.string().optional(),
numItems: z.number().int().min(1).max(100).default(10),
});

app.get("/", (c) => c.json({ message: "Welcome to the cool stuff!" }));

app.get("/number/:number", async (c) => {
try {
const params = mySchema.parse({
//my params
});

const data = await c.env.runQuery(my internalquery with param and pagination);

if (data === null) {
return c.json({ error: " not found" }, 404);
}

return c.json({
status: "success",
data: data.items,
pagination: {
hasMore: data.paginationInfo.hasMore,
nextCursor: data.paginationInfo.continueCursor,
},
metadata: {
//metadata
},
}, 200);
} catch (error) {
console.error("Error processing:", error);
if (error instanceof z.ZodError) {
return c.json({ status: "error", error: "Invalid input", details: error }, 400);
}
return c.json({ status: "error", error: "Internal server error" }, 500);
}
});

app.notFound((c) => c.json({ status: "error", error: "Not found" }, 404));

export default new HttpRouterWithHono(app);
import { Hono } from "hono";
import { HonoWithConvex, HttpRouterWithHono } from "convex-helpers/server/hono";
import { ActionCtx } from "./_generated/server";
import { internal } from "./_generated/api";
import { z } from "zod";

const app: HonoWithConvex<ActionCtx> = new Hono();

const mySchema = z.object({
number: z.string().min(1),
cursor: z.string().optional(),
numItems: z.number().int().min(1).max(100).default(10),
});

app.get("/", (c) => c.json({ message: "Welcome to the cool stuff!" }));

app.get("/number/:number", async (c) => {
try {
const params = mySchema.parse({
//my params
});

const data = await c.env.runQuery(my internalquery with param and pagination);

if (data === null) {
return c.json({ error: " not found" }, 404);
}

return c.json({
status: "success",
data: data.items,
pagination: {
hasMore: data.paginationInfo.hasMore,
nextCursor: data.paginationInfo.continueCursor,
},
metadata: {
//metadata
},
}, 200);
} catch (error) {
console.error("Error processing:", error);
if (error instanceof z.ZodError) {
return c.json({ status: "error", error: "Invalid input", details: error }, 400);
}
return c.json({ status: "error", error: "Internal server error" }, 500);
}
});

app.notFound((c) => c.json({ status: "error", error: "Not found" }, 404));

export default new HttpRouterWithHono(app);
22 replies
CCConvex Community
Created by Hmza on 9/10/2024 in #support-community
can't do 2 crons in file ?
I can't do two same crons in one crons.ts ? params are different but i want to run two crons with different params.
3 replies
CCConvex Community
Created by Hmza on 9/9/2024 in #support-community
i had to calculate data from db. and i ended up using pagination with mutation. fallbacks ?
convex export const getAllDataWithDetails = mutation({ args: { paginationOpts: paginationOptsValidator, filterType: v.string() }, handler: async (ctx, args) => { const { filterType, paginationOpts } = args; const data = await ctx.db .query("data") .filter(q => q.eq(q.field("type"), filterType)) .order("desc") .paginate(paginationOpts); return data; }, }); react const getAllDataWithDetails = useMutation(api.data.export.getAllDataWithDetails); let allData = []; let hasMore = true; let cursor = null; while (hasMore) { const result = await getAllDataWithDetails({ filterType: selectedFilter, paginationOpts: { cursor, numItems: 5000 }, }); allData = [...allData, ...result.page]; hasMore = !result.isDone; cursor = result.continueCursor; } is this all right todo? any fallbacks or suggestions ?
3 replies
CCConvex Community
Created by Hmza on 8/10/2024 in #support-community
Is it possible to add 'Functions breakdown By Time' aswell
Currently the dashboard shows Functions breakdown by dates only. Is it possible to add by time too so the tests can be done on what is consuming what? would be great to have that.
5 replies
CCConvex Community
Created by Hmza on 8/8/2024 in #support-community
one function costed 17GB reads in one day
No description
40 replies
CCConvex Community
Created by Hmza on 4/2/2024 in #support-community
lucia auth with user roles
just starting out with convex and while still learning about schemas and mutations with convex here. how can i add another field in the numbers tables from the example on github, field would be simply users_id to attach user to numbers (which they created) end goal: to create new table with user roles. ref: https://stack.convex.dev/convex-with-lucia import { defineSchema, defineTable } from "convex/server"; import { authTables } from "@convex-dev/convex-lucia-auth"; import { v } from "convex/values"; export default defineSchema( { ...authTables({ user: { email: v.string(), }, session: {}, }), numbers: defineTable({ user: v.id(authTables.users._id) value: v.number(), }), }, { schemaValidation: true }, );
2 replies