-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathinsert.ts
99 lines (94 loc) · 1.99 KB
/
insert.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import randomWords from "random-words";
import { DatabaseWriter, mutation } from "./_generated/server";
import { DataModel } from "./_generated/dataModel";
import { TableNamesInDataModel } from "convex/server";
import { v } from "convex/values";
import { rand } from "./common";
async function insertMessageHelper(
db: DatabaseWriter,
channel: string,
timestamp: number,
rand: number,
ballastCount: number,
count: number,
table: TableNamesInDataModel<DataModel>,
): Promise<void> {
for (let i = 0; i < count; i++) {
const body = randomWords({ exactly: 1 }).join(" ");
const ballastArray = [];
for (let j = 0; j < ballastCount; j++) {
ballastArray.push(j);
}
await db.insert(table, {
channel,
timestamp,
rand,
ballastArray,
body,
});
}
}
export const insertMessage = mutation({
handler: async ({ db }): Promise<void> => {
await insertMessageHelper(
db,
"global",
Date.now(),
rand(),
0,
1,
"messages",
);
},
});
export const insertMessageWithSearch = mutation({
handler: async ({ db }): Promise<void> => {
await insertMessageHelper(
db,
"global",
Date.now(),
rand(),
0,
1,
"messages_with_search",
);
},
});
export const insertLargeMessage = mutation({
args: {},
handler: async ({ db }) => {
await insertMessageHelper(
db,
"large",
Date.now(),
rand(),
4000,
100,
"messages_with_search",
);
},
});
export const insertMessageWithArgs = mutation({
args: {
channel: v.string(),
timestamp: v.number(),
rand: v.number(),
ballastCount: v.number(),
count: v.number(),
table: v.string(),
},
handler: async (
ctx,
{ channel, timestamp, rand, ballastCount, count, table },
) => {
await insertMessageHelper(
ctx.db,
channel,
timestamp,
rand,
ballastCount,
count,
table as TableNamesInDataModel<DataModel>,
);
},
});