-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
30 lines (25 loc) · 785 Bytes
/
Copy pathdb.js
File metadata and controls
30 lines (25 loc) · 785 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
const { Pool } = require("pg");
const connectionString =
process.env.NODE_ENV === "development" ? process.env.DEV_DATABASE_URL : process.env.DATABASE_URL;
const pool = new Pool({ connectionString });
async function connectDB() {
const client = await pool.connect();
try {
await client.query(`
CREATE TABLE IF NOT EXISTS puzzles (
id SERIAL PRIMARY KEY,
index INTEGER UNIQUE NOT NULL,
title TEXT,
date DATE UNIQUE,
board_size INTEGER NOT NULL,
start INTEGER[] NOT NULL,
targets INTEGER[][] NOT NULL,
least_moves INTEGER NOT NULL
);
`);
console.log("Knightle DB setup successful.");
} finally {
client.release();
}
}
module.exports = { pool, connectDB };