-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
35 lines (29 loc) · 888 Bytes
/
Copy pathdb.js
File metadata and controls
35 lines (29 loc) · 888 Bytes
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
const { Pool } = require("pg");
require("dotenv").config();
const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
ssl: { rejectUnauthorized: false }
});
pool.connect()
.then(() => console.log("✅ connected to PostgreSQL"))
.catch(error => {
console.error("database connection error: ", error);
process.exit(1);
});
const query = (text, params) => pool.query(text, params);
async function init_db() {
try {
await query(`
CREATE TABLE IF NOT EXISTS notes (
webhook_hash TEXT PRIMARY KEY,
note_ids TEXT NOT NULL DEFAULT '[]',
pfp_link TEXT NOT NULL DEFAULT '',
username TEXT NOT NULL DEFAULT ''
)
`);
} catch (error) {
console.error("error creating table: ", error);
}
}
init_db();
module.exports = { query };