How to exchange the present database schema config.js?

Asked

Viewed 28 times

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.

  • I get it. I’m gonna try here @Sergio

1 answer

0

My personal mistake...

I did not post the original query here for company security reasons, but in the query had the following field:

vagas_disponíveis

Available accentuated. At the bank too.

The problem was: using psql or dbvis, the query ran normally, but already in Node.js it was error due to the accent. Which I consider correct of course, as there should be no accent on the name of a column - I didn’t do it haha

Just do the column name and change the query and it worked.

Thanks in advance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.