server for my chess game
Diffstat (limited to 'src/pg.js')
| -rw-r--r-- | src/pg.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pg.js b/src/pg.js new file mode 100644 index 0000000..a32abf8 --- /dev/null +++ b/src/pg.js @@ -0,0 +1,27 @@ +const { Pool } = require("pg"); + +const pool = new Pool({ + connectionString: process.env.DATABASE_URL, + ssl: { rejectUnauthorized: false }, +}); + +pool.on("error", (err, client) => { + console.error("Error:", err); +}); + +async function command(command) { + let client; + try { + client = await pool.connect(); + const res = await client.query(command); + return res; + } catch (err) { + console.error(err.stack); + } finally { + client.release(); + } +} + +module.exports = { + command: command, +}; |