From 32db30ebfa7a9bf375a9e4fe06d7e821906d4ef5 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 6 Aug 2021 07:57:37 -0500 Subject: [PATCH] add database endpoints --- server.js | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index ad36975..7cc8128 100644 --- a/server.js +++ b/server.js @@ -54,6 +54,15 @@ new Pool({ port: 5432, }) +const db3 = +new Pool({ + user: 'postgres', + password: '', + host: 'postgres', + database: '', + port: 5432, +}) + const ENDPOINTDATA=[ { endpoint:"class", @@ -202,7 +211,7 @@ const ENDPOINTDATA=[ ] app.get("/databases",(req,res)=>{ - db.query('select * from pg_database where datname like \'ngsplanner%\' limit 100') + db.query('select * from pg_database where datname like \'ngsplanner%\' order by datname limit 100') .then((data)=>{ res.status(200).json(data.rows) }) @@ -211,6 +220,43 @@ app.get("/databases",(req,res)=>{ }) }) +app.post("/databases/testtolive",(req,res)=>{ + db3.query('drop database ngsplanner') + .then(()=>{ + return db3.query('create database ngsplanner with template ngsplanner2') + }) + .then(()=>{ + res.status(200).send("Done!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +app.post("/databases/livetotest",(req,res)=>{ + db3.query('drop database ngsplanner2') + .then(()=>{ + return db3.query('create database ngsplanner2 with template ngsplanner') + }) + .then(()=>{ + res.status(200).send("Done!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +app.post("/databases/backup",(req,res)=>{ + var date = new Date() + db3.query('create database ngsplanner'+String(date.getFullYear()).padStart(4,'0')+String(date.getMonth()).padStart(2,'0')+String(date.getDate()).padStart(2,'0')+String(date.getHours()).padStart(2,'0')+String(date.getMinutes()).padStart(2,'0')+String(date.getSeconds()).padStart(2,'0')+' with template ngsplanner') + .then(()=>{ + res.status(200).send("Done!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + function CreateDynamicEndpoints() { ENDPOINTDATA.map((endpoint)=>{ app.get("/"+endpoint.endpoint,(req,res)=>{