You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: private-path-to-vpc-vsi/ce-job/job.mjs
+28-11Lines changed: 28 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,46 @@ import { LoremIpsum } from "lorem-ipsum";
4
4
const{ Client }=pkg;
5
5
6
6
console.log("Connecting to PostgreSQL instance...");
7
+
8
+
constclient=newClient({
9
+
user: process.env.PGUSER,
10
+
password: process.env.PGPASSWORD,
11
+
host: process.env.PGHOST,
12
+
database: process.env.PGDATABASE,
13
+
port: process.env.PGPORT,
14
+
});
7
15
try{
8
-
constclient=newClient({
9
-
user: process.env.PGUSER,
10
-
password: process.env.PGPASSWORD,
11
-
host: process.env.PGHOST,
12
-
database: process.env.PGDATABASE,
13
-
port: process.env.PGPORT,
14
-
});
15
16
awaitclient.connect();
16
17
17
-
console.log("Creating myfriendships table if it does not exist...");
18
-
awaitclient.query("CREATE TABLE IF NOT EXISTS myfriendships (id SERIAL PRIMARY KEY, name varchar(256) NOT NULL, created_at bigint NOT NULL, greeting text);");
18
+
console.log("Creating guestbook table if it does not exist...");
19
+
awaitclient.query(
20
+
"CREATE TABLE IF NOT EXISTS guestbook (id SERIAL PRIMARY KEY, name varchar(256) NOT NULL, created_at bigint NOT NULL, greeting text);"
21
+
);
19
22
20
-
console.log("Writing into myfriendships table...");
21
-
awaitclient.query("INSERT INTO myfriendships (name,created_at,greeting) VALUES ($1,$2,$3);",[
23
+
console.log("Writing into guestbook table...");
24
+
awaitclient.query("INSERT INTO guestbook (name,created_at,greeting) VALUES ($1,$2,$3);",[
22
25
process.env.HOSTNAME,
23
26
Date.now(),
24
27
newLoremIpsum().generateWords(5),
25
28
]);
26
29
30
+
if(process.env.ACTION==="cleanup"){
31
+
console.log("Cleaning up table content...");
32
+
awaitclient.query("DELETE FROM guestbook;");
33
+
}
34
+
27
35
awaitclient.end();
28
36
console.log("Done!");
29
37
}catch(err){
30
38
console.error("Failed to connect to PostgreSQL instance",err);
0 commit comments