-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (45 loc) · 1.66 KB
/
index.js
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
const {
buildInsertsQuery,
buildManyUpdateQueries,
buildOneUpdateQuery,
} = require("./lib");
const { Client } = require("pg");
const { numberOfInserts, numberOfUpdates } = require("minimist")(
process.argv.slice(2)
);
async function main() {
if (!numberOfInserts || typeof numberOfInserts !== "number") {
console.log("❌ Wrong or missing --numberOfInserts arg");
return;
}
if (!numberOfUpdates || typeof numberOfUpdates !== "number") {
console.log("❌ Wrong or missing --numberOfUpdates arg");
return;
}
if (numberOfUpdates > numberOfInserts) {
console.log("❌ The number of update is higher than the number of insert.");
return;
}
const client = new Client({
user: "postgres",
password: "postgres",
database: "test_db",
});
await client.connect();
await client.query("TRUNCATE TABLE foobar;");
console.log("⌛ Start inserting fake data...");
await client.query(buildInsertsQuery(numberOfInserts));
console.log(`✔️ ${numberOfInserts} rows inserted.`);
console.log("⌛ Running many updates queries...");
const manyUpdatesQueries = buildManyUpdateQueries(numberOfUpdates);
console.time(`✔️ ${numberOfUpdates} updates with many queries in`);
await client.query(manyUpdatesQueries);
console.timeEnd(`✔️ ${numberOfUpdates} updates with many queries in`);
console.log("⌛ Running with one update query...");
const oneUpdateQuery = buildOneUpdateQuery(numberOfUpdates);
console.time(`✔️ ${numberOfUpdates} updates with one query in`);
await client.query(oneUpdateQuery);
console.timeEnd(`✔️ ${numberOfUpdates} updates with one query in`);
await client.end();
}
main();