DCsan
DCsan
CCConvex Community
Created by DCsan on 6/26/2023 in #support-community
helper queries?
I find myself writing a lot of boilerplate helper queries for every class like this. are there any higher level methods for doing this? eg I don't know the internal _id but i have my own IDs for tracking relations across tables. I would like to have my own baseClass for the data tables and just extend to add these common repetitive methods but not sure where/if I can do that. convex is nice that it's all JS, but it doesn't have the convenience of an actual ORM
async function getCardById(db: any, id: string) {
const baseCard = await db
.query("baseCards")
.filter((bc: any) => bc.eq(bc.field("id"), id))
.first();
return baseCard;
}
async function getCardById(db: any, id: string) {
const baseCard = await db
.query("baseCards")
.filter((bc: any) => bc.eq(bc.field("id"), id))
.first();
return baseCard;
}
6 replies
CCConvex Community
Created by DCsan on 6/26/2023 in #support-community
virtual / calculated fields
I'm not sure if Convex really has model classes, but is there a way to extend a schema/model with something like virtual fields? canonical example is you have first, last name fields and want a fullName that just concats them. In my data model, it more just seems pure objects and I'm not even sure if there are underlying classes that I could patch methods onto that can look into the data of the object.
19 replies
CCConvex Community
Created by DCsan on 6/26/2023 in #support-community
pattern for handling failed TXs
if i have a DB mutation that fails, eg buying something but the user doesn't have enough balance... is there a simple way to handle this? eg can a useMutation return a value? should I 'throw' inside the mutation fn and then catch in the main client code? what other options are there? I'd prefer to avoid something like a totally different out-of-band "errors" list
9 replies
CCConvex Community
Created by DCsan on 6/26/2023 in #support-community
better logging / debug output
is there a way to view better debug output? ie formatted json objects? It gets really hard having to manually decode the output I see like:
[CONVEX M(cards:buyCard)] [LOG] 'buyCard' { buyOpts: { user: { _creationTime: 1687745515377.9163, _id: '3nvhb1hwn7qyzha99dt5ctze9h70h0r', id: 'adi', revs: 100 }, userCard: { _creationTime: 1687745513515.5388, _id: '3j7ztxqnwk47azqawexvrb4r9h759f8', cardId: 'whale', lv: 3, user: 'omer' } } }
[CONVEX M(cards:buyCard)] [LOG] 'buyCard' { buyOpts: { user: { _creationTime: 1687745515377.9163, _id: '3nvhb1hwn7qyzha99dt5ctze9h70h0r', id: 'adi', revs: 100 }, userCard: { _creationTime: 1687745513515.5388, _id: '3j7ztxqnwk47azqawexvrb4r9h759f8', cardId: 'whale', lv: 3, user: 'omer' } } }
12 replies
CCConvex Community
Created by DCsan on 6/25/2023 in #support-community
Argument of type 'unknown' is not assignable to parameter of type 'Id<string>'.
The basic tutorials don't work with typescript. eg https://docs.convex.dev/functions/query-functions#query-arguments-and-responses when I try to make a query that takes params, in typescript, eg like this:
export const cards = query(async ({ db }, { id }) => {
return await db.get(id);
});
export const cards = query(async ({ db }, { id }) => {
return await db.get(id);
});
I get this error: Argument of type 'unknown' is not assignable to parameter of type 'Id<string>'. how do i pass params to a query in a way that compiles?
7 replies
CCConvex Community
Created by DCsan on 6/13/2023 in #support-community
subscribe
I'm trying to use this as a realtime DB (firebase replacement) on the SERVER to listen to events. How do i listen for changes on a collection, or subscribe to a query? A bit like useQuery hook but for server side? Or do I have to resort to something with actions?
33 replies
CCConvex Community
Created by DCsan on 6/13/2023 in #support-community
typescript and src/
just getting started with adding to a TS project and stuck right away when I run npx convex dev it creates a convex/_generated in the root level of my project. Instead i keep all my TS code in src/ I tried adding a symlink inside src/convex to the root level _generated
tree src/convex/
src/convex/
├── README.md
├── _generated -> ../../convex/_generated
├── getCards.ts
└── tsconfig.json
tree src/convex/
src/convex/
├── README.md
├── _generated -> ../../convex/_generated
├── getCards.ts
└── tsconfig.json
but getting:
Error: Could not find public function for 'getCards'. Did you forget to run `npx convex dev` or `npx convex deploy`?
Error: Could not find public function for 'getCards'. Did you forget to run `npx convex dev` or `npx convex deploy`?
(the convex dev script is running) is there some other magic I have to set? I note there's also a tsconfig inside the convex dir, with
"include": ["./**/*"],
"exclude": ["./_generated"]
"include": ["./**/*"],
"exclude": ["./_generated"]
I wonder if that will conflict with the rest of my app? also noting the .js files are side by side in the convex output, whereas I usually build all to /dist before deploying. using /src and /dist is fairly standard for a TS project, so maybe I'm missing something why I can't get started
10 replies