How to change the current database schema config.js? [closed]

2

I'm working on an application already developed 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 needs to use schema B .

How do I make this change at run time without changing config.js . Unless there is a configuration in it that does not impact the application.

System query example:

var query = "select * from " + config.bd.schema + ".user_types ;";

The new queries should look like this:

var query = "select * from b.user_types ;";

Error I'm 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.

    
asked by anonymous 19.01.2016 / 12:48

1 answer

0

My personal error ...

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

vagas_disponíveis

Available with an accent . On the bench too.

The problem was: using psql or dbvis, the query executed normally, but already in Node.js it accused error because of the accent. That I consider correct is clear, as there should be no accent in the name of a column - I did not do this haha

I just rename the column and change the query and it worked.

Thank you in advance.

    
19.01.2016 / 18:50