2
I am working on a finished application developed in Node.js/Expressjs.
At the moment my problem is: 95% of the application uses schema A, but the new module I’m creating need to use schema B.
How do I make this change at runtime without changing the config.js. Unless there is a configuration in it that does not impact the application.
Example of system query:
var query = "select * from " + config.bd.schema + ".user_types ;";
The new darlings must be like this:
var query = "select * from b.user_types ;";
Error I am getting
Report.js - getData() >>> column_3 >>> select * from dash.user_types where column_3 = 777
/home/patrick/Workspace/company/project/admin/proj/models/Report.js:69
if(err) throw err;
^
error: syntax error at or near "select"
at Connection.parseE (/home/patrick/Workspace/company/project/admin/proj/node_modules/pg/lib/connection.js:534:11)
at Connection.parseMessage (/home/patrick/Workspace/company/project/admin/proj/node_modules/pg/lib/connection.js:361:17)
at Socket.<anonymous> (/home/patrick/Workspace/company/project/admin/proj/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
config.js
module.exports={
port: 3002,
base: "/",
elms_por_pag:5,
session_timeout:30,
bd:{
host:'localhost',
user:'****',
password:'****',
database:'*****',
schema:'a'
},
email:{
link_email:"http://projetos.exemplo.com.br",
debug:false,
host:"",
port:0,
name:"Projeto",
secure:true,
username:"",
password:""
}
}
If you need more information, let me know.
How about in the new module do
var configB = JSON.parse(JSON.stringify(require('./config'))); configB.bd.schema = 'b';
That way inside the module you have the right config. Or create an entry in this config.js for other modules. It all depends on whether it’s an exception or worth rethinking the logic.– Sergio
I get it. I’m gonna try here @Sergio
– Patrick Maciel