Skip to content

Commit

Permalink
initial for database connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 20, 2021
1 parent 2be48fe commit b84e10e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"wa-canvas": "git+https://github.com/Kry9toN/wa-canvas.git",
"release-it": "^14.2.2",
"cfonts": "^2.9.1",
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"pg": "^8.5.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
32 changes: 32 additions & 0 deletions utils/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { Pool } = require('pg')
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 2500,
idleTimeoutMillis: 2000,
max: 10000
})

const databaseInput = (value) => new Promise((resolve, reject) => {
pool.query(value, (err, result) => {
if (err) {
console.error(err)
reject(err)
}
resolve(result)
})
})

const databaseView = (value) => new Promise((resolve, reject) => {
pool.query(value, (err, result) => {
if (err) {
console.error(err)
reject(err)
}
resolve(result.rows)
})
})

module.exports = {
databaseView,
databaseInput
}

0 comments on commit b84e10e

Please sign in to comment.