Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion convex/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const incrementCounter = mutation({
});
} else {
counterDoc.counter += increment;
await ctx.db.replace(counterDoc._id, counterDoc);
await ctx.db.replace("counter_table", counterDoc._id, counterDoc);
}
},
});
6 changes: 3 additions & 3 deletions convex/migrationsExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const increment = migration({
export const cleanUpBrokenRefs = migration({
table: "join_table_example",
migrateOne: async (ctx, doc) => {
const user = await ctx.db.get(doc.userId);
const presence = await ctx.db.get(doc.presenceId);
const user = await ctx.db.get("users", doc.userId);
const presence = await ctx.db.get("presence", doc.presenceId);
if (!user || !presence) {
await ctx.db.delete(doc._id);
await ctx.db.delete("join_table_example", doc._id);
}
},
});
Expand Down
4 changes: 2 additions & 2 deletions convex/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const update = mutation({
.withIndex("user_room", (q) => q.eq("user", user).eq("room", room))
.unique();
if (existing) {
await db.patch(existing._id, { data, updated: Date.now() });
await db.patch("presence", existing._id, { data, updated: Date.now() });
} else {
await db.insert("presence", {
user,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const heartbeat = mutation({
.withIndex("user_room", (q) => q.eq("user", user).eq("room", room))
.unique();
if (existing) {
await db.patch(existing._id, { updated: Date.now() });
await db.patch("presence", existing._id, { updated: Date.now() });
}
},
});
Expand Down
14 changes: 7 additions & 7 deletions convex/relationshipsExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const relationshipTest = mutation({
(await getAllOrThrow(ctx.db, userIds)).map(assertNotNull);

// Now let's delete one and see if everything behaves as we expect
await ctx.db.delete(user2._id);
await ctx.db.delete("users", user2._id);
assertNull(await getOneFrom(ctx.db, "users", "tokenIdentifier", "test456"));
assertHasNull(await getAll(ctx.db, userIds));
try {
Expand All @@ -106,7 +106,7 @@ export const relationshipTest = mutation({
console.log("Successfully caught missing userId");
}

await ctx.db.delete(presenceId2);
await ctx.db.delete("presence", presenceId2);
assertHasNull(
await getManyVia(
ctx.db,
Expand All @@ -127,10 +127,10 @@ export const relationshipTest = mutation({
} catch {
console.log("Successfully caught missing presenceId");
}
await asyncMap(edges, (edge) => ctx.db.delete(edge._id));
await asyncMap(edges, (edge) => ctx.db.delete("join_table_example", edge._id));
await asyncMap(
await getManyFrom(ctx.db, "join_table_example", "by_userId", user2._id),
(edge) => ctx.db.delete(edge._id),
(edge) => ctx.db.delete("join_table_example", edge._id),
);

// Testing custom index names
Expand All @@ -144,7 +144,7 @@ export const relationshipTest = mutation({
(await getManyFrom(ctx.db, "presence", "user_room", userId, "user")).map(
assertNotNull,
);
await ctx.db.delete(presenceId);
await ctx.db.delete("presence", presenceId);

const file = await ctx.db.system.query("_storage").first();
if (!file) {
Expand Down Expand Up @@ -180,8 +180,8 @@ export const relationshipTest = mutation({
"userId",
)
).map(assertNotNull);
await ctx.db.delete(userId);
await ctx.db.delete(edgeId);
await ctx.db.delete("users", userId);
await ctx.db.delete("join_storage_example", edgeId);

return true;
},
Expand Down
2 changes: 1 addition & 1 deletion convex/rlsExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ export const updateName = mutationWithRLS({
// will prevent you from modifying other users.
args: { name: v.string(), userId: v.id("users") },
handler: async (ctx, { name, userId }) => {
await ctx.db.patch(userId, { name });
await ctx.db.patch("users", userId, { name });
},
});
6 changes: 3 additions & 3 deletions convex/sessionsExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const logIn = mutationWithSession({
.withIndex("user_room", (q) => q.eq("user", ctx.sessionId))
.collect();
await Promise.all(
presenceDocs.map((doc) => ctx.db.patch(doc._id, { user: args.new })),
presenceDocs.map((doc) => ctx.db.patch("presence", doc._id, { user: args.new })),
);
},
});
Expand All @@ -144,7 +144,7 @@ export const logOut = mutationWithSession({
.query("presence")
.withIndex("user_room", (q) => q.eq("user", ctx.sessionId))
.collect();
await Promise.all(presenceDocs.map((doc) => ctx.db.delete(doc._id)));
await Promise.all(presenceDocs.map((doc) => ctx.db.delete("presence", doc._id)));
},
});

Expand Down Expand Up @@ -183,7 +183,7 @@ export const joinRoom = mutationWithSession({
)
.first();
if (existing) {
await ctx.db.patch(existing._id, { updated: Date.now() });
await ctx.db.patch("presence", existing._id, { updated: Date.now() });
} else {
await ctx.db.insert("presence", {
user: ctx.sessionId,
Expand Down
2 changes: 1 addition & 1 deletion convex/testingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const clearAll = testingMutation({
handler: async ({ db, scheduler, storage }) => {
for (const table of Object.keys(schema.tables)) {
const docs = await db.query(table as any).collect();
await Promise.all(docs.map((doc) => db.delete(doc._id)));
await Promise.all(docs.map((doc) => db.delete(table, doc._id)));
}
const scheduled = await db.system.query("_scheduled_functions").collect();
await Promise.all(scheduled.map((s) => scheduler.cancel(s._id)));
Expand Down
16 changes: 8 additions & 8 deletions convex/triggersExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ triggers.register("counter_table", async (ctx, change) => {
// Round up to the nearest multiple of 10, one at a time.
// This demonstrates that triggers can trigger themselves.
console.log("Incrementing counter to", change.newDoc.counter + 1);
await ctx.db.patch(change.newDoc._id, {
await ctx.db.patch("counter_table", change.newDoc._id, {
counter: change.newDoc.counter + 1,
});
}
Expand Down Expand Up @@ -55,13 +55,13 @@ triggers.register("counter_table", async (ctx, change) => {
}
const sumDoc = (await ctx.db.query("sum_table").first())!;
if (change.operation === "insert") {
await ctx.db.patch(sumDoc._id, { sum: sumDoc.sum + change.newDoc.counter });
await ctx.db.patch("sum_table", sumDoc._id, { sum: sumDoc.sum + change.newDoc.counter });
} else if (change.operation === "update") {
await ctx.db.patch(sumDoc._id, {
await ctx.db.patch("sum_table", sumDoc._id, {
sum: sumDoc.sum + change.newDoc.counter - change.oldDoc.counter,
});
} else if (change.operation === "delete") {
await ctx.db.patch(sumDoc._id, { sum: sumDoc.sum - change.oldDoc.counter });
await ctx.db.patch("sum_table", sumDoc._id, { sum: sumDoc.sum - change.oldDoc.counter });
}
});

Expand All @@ -88,9 +88,9 @@ export const incrementCounterRace = mutation({
throw new Error("No counters");
}
await Promise.all([
db.patch(firstCounter._id, { counter: firstCounter.counter + 1 }),
db.patch(firstCounter._id, { counter: firstCounter.counter + 2 }),
db.patch(firstCounter._id, { counter: firstCounter.counter + 3 }),
db.patch("counter_table", firstCounter._id, { counter: firstCounter.counter + 1 }),
db.patch("counter_table", firstCounter._id, { counter: firstCounter.counter + 2 }),
db.patch("counter_table", firstCounter._id, { counter: firstCounter.counter + 3 }),
]);
},
});
Expand Down Expand Up @@ -140,6 +140,6 @@ export const updateName = mutationWithRLS({
handler: async (ctx, { name, userId }) => {
// The extra type from above still comes through
console.log(ctx.foo);
await ctx.db.patch(userId, { name });
await ctx.db.patch("users", userId, { name });
},
});
105 changes: 46 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.18.2",
"@convex-dev/eslint-plugin": "1.0.0",
"@convex-dev/eslint-plugin": "1.1.1",
"@edge-runtime/vm": "5.0.0",
"@eslint/js": "9.39.1",
"@redocly/cli": "2.11.1",
Expand Down
Loading
Loading