import { v } from 'convex/values'
import { internal } from './_generated/api'
import { action, internalMutation } from './_generated/server'
/**
* Updates the table values for a given groupId
*/
export const processGroup = internalMutation({
args: { groupId: v.string() },
handler: async (ctx, { groupId }) => {
// Get all existing docs with this groupId
const existingDocs = await ctx.db
.query('testDocs')
.filter((q) => q.eq(q.field('groupId'), groupId))
.collect()
for (const existingDoc of existingDocs) {
await ctx.db.delete(existingDoc._id)
}
for (let i = 0; i < 10; i++) {
await ctx.db.insert('testDocs', { groupId, value: i.toString() })
}
}
})
export const trigger = action({
handler: async (ctx) => {
const groupIds: string[] = []
for (let i = 0; i < 10; i++) {
groupIds.push(i.toString())
}
await Promise.all(
groupIds.map(async (groupId) => {
await ctx.runMutation(internal.dbTest.processGroup, { groupId })
})
)
}
})
import { v } from 'convex/values'
import { internal } from './_generated/api'
import { action, internalMutation } from './_generated/server'
/**
* Updates the table values for a given groupId
*/
export const processGroup = internalMutation({
args: { groupId: v.string() },
handler: async (ctx, { groupId }) => {
// Get all existing docs with this groupId
const existingDocs = await ctx.db
.query('testDocs')
.filter((q) => q.eq(q.field('groupId'), groupId))
.collect()
for (const existingDoc of existingDocs) {
await ctx.db.delete(existingDoc._id)
}
for (let i = 0; i < 10; i++) {
await ctx.db.insert('testDocs', { groupId, value: i.toString() })
}
}
})
export const trigger = action({
handler: async (ctx) => {
const groupIds: string[] = []
for (let i = 0; i < 10; i++) {
groupIds.push(i.toString())
}
await Promise.all(
groupIds.map(async (groupId) => {
await ctx.runMutation(internal.dbTest.processGroup, { groupId })
})
)
}
})