export const upsertPost = mutation({
args: { documents: v.array(schema.tables.posts.validator) },
handler: async (ctx, { documents }) => {
await Promise.all(
documents.map(async (doc) => {
const existing = await ctx.db
.query('posts')
.filter((q) => q.eq(q.field('id'), doc.id))
.first();
if (existing) {
return ctx.db.replace(existing._id, doc);
} else {
return ctx.db.insert('posts', doc);
}
})
);
}
});
export const upsertPost = mutation({
args: { documents: v.array(schema.tables.posts.validator) },
handler: async (ctx, { documents }) => {
await Promise.all(
documents.map(async (doc) => {
const existing = await ctx.db
.query('posts')
.filter((q) => q.eq(q.field('id'), doc.id))
.first();
if (existing) {
return ctx.db.replace(existing._id, doc);
} else {
return ctx.db.insert('posts', doc);
}
})
);
}
});