Connect to Azure Functions Database (Javascript)

Asked

Viewed 38 times

1

all right?

I’ve been facing a constant problem, and I don’t know what else to try to solve it.

I created an Azure Function and need to query some data in the database in order to return them as function response.

I created a Postgresql Database in Azure, added the IP in the firewall, added the IP of my machine and created tables, and everything else.

However, when trying to connect to the database within the Azure Function, you simply do not return anything, or connect.

What to do about it?

From now on, thank you!

My code:

module.exports = function (context, req) {
    const pg = require('pg');

    // Connect to DB with Long String in App Settings

    const client = new pg.Client(GetEnvironmentVariable("AzurePGDB"));
    client.connect();
    const query = 'select * from table';

    client.query(query, (err, res) => {
        context.res = {
           body: res
        }
    });

   context.done();
};

function GetEnvironmentVariable(name) {
    return name + ": " + process.env[name];
}
No answers

Browser other questions tagged

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