#Best practice to store "callbacks" in database?

3 messages · Page 1 of 1 (latest)

arctic swallow
#

For example, let's say I have a JS interface for game achievement:

type Achievement = {
  title: string;

  // based on user's game data, return whether the criteria of this achievement is met or not
  isCriteriaMet: (ctx: UserGameData) => boolean;
  
  // if criteria is met, reward user by running this function to mutate user's data
  reward: () => void;
}

What is the best practice to represent this in Convex DB? Or in any DB?

My thought is to store reference to a query function (in my code) in isCriteriaMet field; store reference to a mutation function in reward field. Or maybe just references to helper functions with context?

If implemented this way, is there a Convex internal API where I can sync the list of query/mutation functions I defined in my code to the Convex DB, so I can safely reference them in another table?

compact ravineBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

  • Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
  • Use search.convex.dev to search Docs, Stack, and Discord all at once.
  • Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
  • Avoid tagging staff unless specifically instructed.

Thank you!

random scarab
#

Welcome! Apart from the specific approach you’ve outlined, this is a pretty simple use case - you would determine if criteria is met at runtime in your Convex function.